Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: nilerr, a new linter rule (#1991)

p0nyeb13f2adb0dc
diff --git a/.golangci.yaml b/.golangci.yaml
index 512e97b5c5..4b0434f685 100644
--- a/.golangci.yaml
+++ b/.golangci.yaml
@@ -9,6 +9,7 @@ linters:
- gocritic
- sqlclosecheck
- rowserrcheck
+ - nilerr
# golangci-lint run --exclude="Rollback,logger.Sync,pgInstance.Stop"
issues:
diff --git a/enterprise/service/license.go b/enterprise/service/license.go
index f1005bc2e7..62be76c64a 100644
--- a/enterprise/service/license.go
+++ b/enterprise/service/license.go
@@ -44,7 +44,7 @@ func NewLicenseService(mode common.ReleaseMode, store *store.Store) (*LicenseSer
func (s *LicenseService) StoreLicense(patch *enterpriseAPI.SubscriptionPatch) error {
if patch.License != "" {
if _, err := s.parseLicense(patch.License); err != nil {
- return nil
+ return err
}
}
return s.writeLicense(patch)
diff --git a/plugin/advisor/mysql/advisor_syntax.go b/plugin/advisor/mysql/advisor_syntax.go
index 2dbe396579..946ae1d3dd 100644
--- a/plugin/advisor/mysql/advisor_syntax.go
+++ b/plugin/advisor/mysql/advisor_syntax.go
@@ -23,6 +23,7 @@ func (adv *SyntaxAdvisor) Check(ctx advisor.Context, statement string) ([]adviso
_, warns, err := p.Parse(statement, ctx.Charset, ctx.Collation)
if err != nil {
+ //nolint:nilerr
return []advisor.Advice{
{
Status: advisor.Error,
diff --git a/plugin/db/snowflake/snowflake.go b/plugin/db/snowflake/snowflake.go
index 4befd18b1b..4f55917850 100644
--- a/plugin/db/snowflake/snowflake.go
+++ b/plugin/db/snowflake/snowflake.go
@@ -231,7 +231,7 @@ func (driver *Driver) Execute(ctx context.Context, statement string) error {
}
if err := driver.useRole(ctx, sysAdminRole); err != nil {
- return nil
+ return err
}
tx, err := driver.db.BeginTx(ctx, nil)
if err != nil {
diff --git a/plugin/vcs/internal/oauth/oauth.go b/plugin/vcs/internal/oauth/oauth.go
index 921acae51f..59312ab4c5 100644
--- a/plugin/vcs/internal/oauth/oauth.go
+++ b/plugin/vcs/internal/oauth/oauth.go
@@ -122,6 +122,7 @@ func getOAuthErrorDetails(code int, body []byte) error {
var oe oauthError
if err := json.Unmarshal(body, &oe); err != nil {
// If we failed to unmarshal body with oauth error, it's not oauthError and we should return nil.
+ //nolint:nilerr
return nil
}
// https://www.oauth.com/oauth2-servers/access-tokens/access-token-response/
diff --git a/server/subscription.go b/server/subscription.go
index 9ff5bfb626..9c20efe511 100644
--- a/server/subscription.go
+++ b/server/subscription.go
@@ -31,6 +31,9 @@ func (s *Server) registerSubscriptionRoutes(g *echo.Group) {
patch.UpdaterID = c.Get(getPrincipalIDContextKey()).(int)
if err := s.LicenseService.StoreLicense(patch); err != nil {
+ if common.ErrorCode(err) == common.Invalid {
+ return echo.NewHTTPError(http.StatusBadRequest, err.Error()).SetInternal(err)
+ }
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to store license").SetInternal(err)
}
diff --git a/tests/mysql_prepare.go b/tests/mysql_prepare.go
index c97dab6e2e..a3a8500ff1 100644
--- a/tests/mysql_prepare.go
+++ b/tests/mysql_prepare.go
@@ -23,7 +23,7 @@ KEY k_1 (k)
)`
db, err := connectTestMySQL(port, "")
if err != nil {
- return nil
+ return err
}
defer db.Close()