Chore: a bit of spring cleaning (#16710)
* Chore: use early return technic everywhere And enable "indent-error-flow" revive rule * Chore: remove if-return rule from revive config * Chore: improve error messages And enable "error-strings" revive rule * Chore: enable "error-naming" revive rule * Chore: make linter happy * Chore: do not duplicate gofmt execution * Chore: make linter happy * Chore: address the pull review comments
This commit is contained in:
@@ -213,11 +213,12 @@ func getAlertNotificationWithUidInternal(query *m.GetAlertNotificationsWithUidQu
|
||||
func CreateAlertNotificationCommand(cmd *m.CreateAlertNotificationCommand) error {
|
||||
return inTransaction(func(sess *DBSession) error {
|
||||
if cmd.Uid == "" {
|
||||
if uid, uidGenerationErr := generateNewAlertNotificationUid(sess, cmd.OrgId); uidGenerationErr != nil {
|
||||
uid, uidGenerationErr := generateNewAlertNotificationUid(sess, cmd.OrgId)
|
||||
if uidGenerationErr != nil {
|
||||
return uidGenerationErr
|
||||
} else {
|
||||
cmd.Uid = uid
|
||||
}
|
||||
|
||||
cmd.Uid = uid
|
||||
}
|
||||
existingQuery := &m.GetAlertNotificationsWithUidQuery{OrgId: cmd.OrgId, Uid: cmd.Uid}
|
||||
err := getAlertNotificationWithUidInternal(existingQuery, sess)
|
||||
|
||||
@@ -35,7 +35,7 @@ func makeCert(tlsPoolName string, config DatabaseConfig) (*tls.Config, error) {
|
||||
}
|
||||
// Return more meaningful error before it is too late
|
||||
if config.ServerCertName == "" && !tlsConfig.InsecureSkipVerify {
|
||||
return nil, fmt.Errorf("server_cert_name is missing. Consider using ssl_mode = skip-verify.")
|
||||
return nil, fmt.Errorf("server_cert_name is missing. Consider using ssl_mode = skip-verify")
|
||||
}
|
||||
return tlsConfig, nil
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@ import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
)
|
||||
|
||||
var ProvokedError = errors.New("testing error.")
|
||||
var ErrProvokedError = errors.New("testing error")
|
||||
|
||||
func TestTransaction(t *testing.T) {
|
||||
ss := InitTestDB(t)
|
||||
@@ -42,10 +42,10 @@ func TestTransaction(t *testing.T) {
|
||||
return err
|
||||
}
|
||||
|
||||
return ProvokedError
|
||||
return ErrProvokedError
|
||||
})
|
||||
|
||||
So(err, ShouldEqual, ProvokedError)
|
||||
So(err, ShouldEqual, ErrProvokedError)
|
||||
|
||||
query := &models.GetApiKeyByIdQuery{ApiKeyId: cmd.Result.Id}
|
||||
err = GetApiKeyById(query)
|
||||
|
||||
@@ -2,12 +2,11 @@ package sqlstore
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana/pkg/bus"
|
||||
"github.com/grafana/grafana/pkg/events"
|
||||
m "github.com/grafana/grafana/pkg/models"
|
||||
@@ -48,16 +47,15 @@ func getOrgIdForNewUser(cmd *m.CreateUserCommand, sess *DBSession) (int64, error
|
||||
}
|
||||
if has {
|
||||
return org.Id, nil
|
||||
}
|
||||
if setting.AutoAssignOrgId == 1 {
|
||||
org.Name = "Main Org."
|
||||
org.Id = int64(setting.AutoAssignOrgId)
|
||||
} else {
|
||||
if setting.AutoAssignOrgId == 1 {
|
||||
org.Name = "Main Org."
|
||||
org.Id = int64(setting.AutoAssignOrgId)
|
||||
} else {
|
||||
sqlog.Info("Could not create user: organization id %v does not exist",
|
||||
setting.AutoAssignOrgId)
|
||||
return 0, fmt.Errorf("Could not create user: organization id %v does not exist",
|
||||
setting.AutoAssignOrgId)
|
||||
}
|
||||
sqlog.Info("Could not create user: organization id %v does not exist",
|
||||
setting.AutoAssignOrgId)
|
||||
return 0, fmt.Errorf("Could not create user: organization id %v does not exist",
|
||||
setting.AutoAssignOrgId)
|
||||
}
|
||||
} else {
|
||||
org.Name = cmd.OrgName
|
||||
|
||||
Reference in New Issue
Block a user