Chore: Fix staticcheck issues (#28854)
* Chore: Fix issues reported by staticcheck Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com> * Undo changes Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
@@ -286,7 +286,7 @@ func SetAlertState(cmd *models.SetAlertStateCommand) error {
|
||||
if has, err := sess.ID(cmd.AlertId).Get(&alert); err != nil {
|
||||
return err
|
||||
} else if !has {
|
||||
return fmt.Errorf("Could not find alert")
|
||||
return fmt.Errorf("could not find alert")
|
||||
}
|
||||
|
||||
if alert.State == models.AlertStatePaused {
|
||||
|
||||
@@ -390,7 +390,7 @@ func UpdateAlertNotification(cmd *models.UpdateAlertNotificationCommand) error {
|
||||
}
|
||||
|
||||
if sameNameQuery.Result != nil && sameNameQuery.Result.Id != current.Id {
|
||||
return fmt.Errorf("Alert notification name %s already exists", cmd.Name)
|
||||
return fmt.Errorf("alert notification name %q already exists", cmd.Name)
|
||||
}
|
||||
|
||||
// delete empty keys
|
||||
@@ -431,7 +431,7 @@ func UpdateAlertNotification(cmd *models.UpdateAlertNotificationCommand) error {
|
||||
if affected, err := sess.ID(cmd.Id).Update(current); err != nil {
|
||||
return err
|
||||
} else if affected == 0 {
|
||||
return fmt.Errorf("Could not update alert notification")
|
||||
return fmt.Errorf("could not update alert notification")
|
||||
}
|
||||
|
||||
cmd.Result = ¤t
|
||||
@@ -578,7 +578,7 @@ func GetOrCreateAlertNotificationState(ctx context.Context, cmd *models.GetOrCre
|
||||
}
|
||||
|
||||
if !exist {
|
||||
return errors.New("Should not happen")
|
||||
return errors.New("should not happen")
|
||||
}
|
||||
|
||||
cmd.Result = nj
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
func validateTimeRange(item *annotations.Item) error {
|
||||
if item.EpochEnd == 0 {
|
||||
if item.Epoch == 0 {
|
||||
return errors.New("Missing Time Range")
|
||||
return errors.New("missing time range")
|
||||
}
|
||||
item.EpochEnd = item.Epoch
|
||||
}
|
||||
@@ -78,7 +78,7 @@ func (r *SqlAnnotationRepo) Update(item *annotations.Item) error {
|
||||
return err
|
||||
}
|
||||
if !isExist {
|
||||
return errors.New("Annotation not found")
|
||||
return errors.New("annotation not found")
|
||||
}
|
||||
|
||||
existing.Updated = timeNow().UnixNano() / int64(time.Millisecond)
|
||||
|
||||
@@ -39,12 +39,10 @@ func DeleteOldLoginAttempts(cmd *models.DeleteOldLoginAttemptsCommand) error {
|
||||
var maxId int64
|
||||
sql := "SELECT max(id) as id FROM login_attempt WHERE created < ?"
|
||||
result, err := sess.Query(sql, cmd.OlderThan.Unix())
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// nolint: gosimple
|
||||
if result == nil || len(result) == 0 || result[0] == nil {
|
||||
if len(result) == 0 || result[0] == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ func (ss *SqlStore) ensureMainOrgAndAdminUser() error {
|
||||
systemUserCountQuery := models.GetSystemUserCountStatsQuery{}
|
||||
err := bus.DispatchCtx(ctx, &systemUserCountQuery)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Could not determine if admin user exists: %v", err)
|
||||
return fmt.Errorf("could not determine if admin user exists: %w", err)
|
||||
}
|
||||
|
||||
if systemUserCountQuery.Result.Count > 0 {
|
||||
@@ -132,7 +132,7 @@ func (ss *SqlStore) ensureMainOrgAndAdminUser() error {
|
||||
cmd.IsAdmin = true
|
||||
|
||||
if err := bus.DispatchCtx(ctx, &cmd); err != nil {
|
||||
return fmt.Errorf("Failed to create admin user: %v", err)
|
||||
return fmt.Errorf("failed to create admin user: %s", err)
|
||||
}
|
||||
|
||||
ss.log.Info("Created default admin", "user", setting.AdminUser)
|
||||
@@ -226,7 +226,7 @@ func (ss *SqlStore) buildConnectionString() (string, error) {
|
||||
cnnstr = fmt.Sprintf("file:%s?cache=%s&mode=rwc", ss.dbCfg.Path, ss.dbCfg.CacheMode)
|
||||
cnnstr += ss.buildExtraConnectionString('&')
|
||||
default:
|
||||
return "", fmt.Errorf("Unknown database type: %s", ss.dbCfg.Type)
|
||||
return "", fmt.Errorf("unknown database type: %s", ss.dbCfg.Type)
|
||||
}
|
||||
|
||||
return cnnstr, nil
|
||||
|
||||
@@ -15,7 +15,7 @@ func makeCert(config DatabaseConfig) (*tls.Config, error) {
|
||||
rootCertPool := x509.NewCertPool()
|
||||
pem, err := ioutil.ReadFile(config.CaCertPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Could not read DB CA Cert path: %v", config.CaCertPath)
|
||||
return nil, fmt.Errorf("could not read DB CA Cert path %q: %w", config.CaCertPath, err)
|
||||
}
|
||||
if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user