Skip to content

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

fix: make `common.Errorf` support formatting (#1998)

Joe Chene45acefcd6ed
diff --git a/.golangci.yaml b/.golangci.yaml
index 4b0434f685..79d8caa181 100644
--- a/.golangci.yaml
+++ b/.golangci.yaml
@@ -83,3 +83,8 @@ linters-settings:
gocritic:
disabled-checks:
- ifElseChain
+ govet:
+ settings:
+ printf: # The name of the analyzer, run `go tool vet help` to see the list of all analyzers
+ funcs: # Run `go tool vet help printf` to see the full configuration of `printf`
+ - common.Errorf
diff --git a/api/deploy.go b/api/deploy.go
index b21510b464..c0522febee 100644
--- a/api/deploy.go
+++ b/api/deploy.go
@@ -2,7 +2,6 @@ package api
import (
"encoding/json"
- "fmt"
"github.com/bytebase/bytebase/common"
)
@@ -110,31 +109,31 @@ func ValidateAndGetDeploymentSchedule(payload string) (*DeploymentSchedule, erro
for _, d := range schedule.Deployments {
if d.Name == "" {
- return nil, common.Errorf(common.Invalid, fmt.Errorf("Deployment name must not be empty"))
+ return nil, common.Errorf(common.Invalid, "Deployment name must not be empty")
}
hasEnv := false
for _, e := range d.Spec.Selector.MatchExpressions {
switch e.Operator {
case InOperatorType:
if len(e.Values) == 0 {
- return nil, common.Errorf(common.Invalid, fmt.Errorf("expression key %q with %q operator should have at least one value", e.Key, e.Operator))
+ return nil, common.Errorf(common.Invalid, "expression key %q with %q operator should have at least one value", e.Key, e.Operator)
}
case ExistsOperatorType:
if len(e.Values) > 0 {
- return nil, common.Errorf(common.Invalid, fmt.Errorf("expression key %q with %q operator shouldn't have values", e.Key, e.Operator))
+ return nil, common.Errorf(common.Invalid, "expression key %q with %q operator shouldn't have values", e.Key, e.Operator)
}
default:
- return nil, common.Errorf(common.Invalid, fmt.Errorf("expression key %q has invalid operator %q", e.Key, e.Operator))
+ return nil, common.Errorf(common.Invalid, "expression key %q has invalid operator %q", e.Key, e.Operator)
}
if e.Key == EnvironmentKeyName {
hasEnv = true
if e.Operator != InOperatorType || len(e.Values) != 1 {
- return nil, common.Errorf(common.Invalid, fmt.Errorf("label %q should must use operator %q with exactly one value", EnvironmentKeyName, InOperatorType))
+ return nil, common.Errorf(common.Invalid, "label %q should must use operator %q with exactly one value", EnvironmentKeyName, InOperatorType)
}
}
}
if !hasEnv {
- return nil, common.Errorf(common.Invalid, fmt.Errorf("deployment should contain %q label", EnvironmentKeyName))
+ return nil, common.Errorf(common.Invalid, "deployment should contain %q label", EnvironmentKeyName)
}
}
return schedule, nil
diff --git a/common/error.go b/common/error.go
index 1cc56e83fb..dc137a7261 100644
--- a/common/error.go
+++ b/common/error.go
@@ -85,8 +85,17 @@ func ErrorMessage(err error) string {
return "Internal error."
}
-// Errorf is a helper function to return an Error with a given code and error.
-func Errorf(code Code, err error) *Error {
+// Errorf is a helper function to return an Error with given code, format and
+// arguments.
+func Errorf(code Code, format string, args ...interface{}) *Error {
+ return &Error{
+ Code: code,
+ Err: fmt.Errorf(format, args...),
+ }
+}
+
+// WithError is a helper function to return an Error with given code and error.
+func WithError(code Code, err error) *Error {
return &Error{
Code: code,
Err: err,
@@ -95,5 +104,5 @@ func Errorf(code Code, err error) *Error {
// FormatDBErrorEmptyRowWithQuery formats database error that query returns empty row.
func FormatDBErrorEmptyRowWithQuery(query string) error {
- return Errorf(DbExecutionError, fmt.Errorf("query %q returned empty row", query))
+ return Errorf(DbExecutionError, "query %q returned empty row", query)
}
diff --git a/enterprise/service/license.go b/enterprise/service/license.go
index 62be76c64a..d5c915c5c0 100644
--- a/enterprise/service/license.go
+++ b/enterprise/service/license.go
@@ -4,12 +4,13 @@ import (
"context"
"fmt"
+ "github.com/golang-jwt/jwt/v4"
+
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
enterpriseAPI "github.com/bytebase/bytebase/enterprise/api"
"github.com/bytebase/bytebase/enterprise/config"
"github.com/bytebase/bytebase/store"
- "github.com/golang-jwt/jwt/v4"
)
// LicenseService is the service for enterprise license.
@@ -57,7 +58,7 @@ func (s *LicenseService) LoadLicense() (*enterpriseAPI.License, error) {
return nil, err
}
if tokenString == "" {
- return nil, common.Errorf(common.NotFound, fmt.Errorf("cannot find license"))
+ return nil, common.Errorf(common.NotFound, "cannot find license")
}
return s.parseLicense(tokenString)
@@ -67,27 +68,27 @@ func (s *LicenseService) parseLicense(license string) (*enterpriseAPI.License, e
claims := &Claims{}
token, err := jwt.ParseWithClaims(license, claims, func(token *jwt.Token) (interface{}, error) {
if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok {
- return nil, common.Errorf(common.Invalid, fmt.Errorf("unexpected signing method: %v", token.Header["alg"]))
+ return nil, common.Errorf(common.Invalid, "unexpected signing method: %v", token.Header["alg"])
}
kid, ok := token.Header["kid"].(string)
if !ok || kid != s.config.Version {
- return nil, common.Errorf(common.Invalid, fmt.Errorf("version '%v' is not valid. expect %s", token.Header["kid"], s.config.Version))
+ return nil, common.Errorf(common.Invalid, "version '%v' is not valid. expect %s", token.Header["kid"], s.config.Version)
}
key, err := jwt.ParseRSAPublicKeyFromPEM([]byte(s.config.PublicKey))
if err != nil {
- return nil, common.Errorf(common.Invalid, err)
+ return nil, common.WithError(common.Invalid, err)
}
return key, nil
})
if err != nil {
- return nil, common.Errorf(common.Invalid, err)
+ return nil, common.WithError(common.Invalid, err)
}
if !token.Valid {
- return nil, common.Errorf(common.Invalid, fmt.Errorf("invalid token"))
+ return nil, common.Errorf(common.Invalid, "invalid token")
}
return s.parseClaims(claims)
@@ -97,27 +98,27 @@ func (s *LicenseService) parseLicense(license string) (*enterpriseAPI.License, e
func (s *LicenseService) parseClaims(claims *Claims) (*enterpriseAPI.License, error) {
err := claims.Valid()
if err != nil {
- return nil, common.Errorf(common.Invalid, err)
+ return nil, common.WithError(common.Invalid, err)
}
verifyIssuer := claims.VerifyIssuer(s.config.Issuer, true)
if !verifyIssuer {
- return nil, common.Errorf(common.Invalid, fmt.Errorf("iss is not valid, expect %s but found '%v'", s.config.Issuer, claims.Issuer))
+ return nil, common.Errorf(common.Invalid, "iss is not valid, expect %s but found '%v'", s.config.Issuer, claims.Issuer)
}
verifyAudience := claims.VerifyAudience(s.config.Audience, true)
if !verifyAudience {
- return nil, common.Errorf(common.Invalid, fmt.Errorf("aud is not valid, expect %s but found '%v'", s.config.Audience, claims.Audience))
+ return nil, common.Errorf(common.Invalid, "aud is not valid, expect %s but found '%v'", s.config.Audience, claims.Audience)
}
instanceCount := claims.InstanceCount
if instanceCount < s.config.MinimumInstance {
- return nil, common.Errorf(common.Invalid, fmt.Errorf("license instance count '%v' is not valid, minimum instance requirement is %d", instanceCount, s.config.MinimumInstance))
+ return nil, common.Errorf(common.Invalid, "license instance count '%v' is not valid, minimum instance requirement is %d", instanceCount, s.config.MinimumInstance)
}
planType, err := convertPlanType(claims.Plan)
if err != nil {
- return nil, common.Errorf(common.Invalid, fmt.Errorf("plan type %q is not valid", planType))
+ return nil, common.Errorf(common.Invalid, "plan type %q is not valid", planType)
}
license := &enterpriseAPI.License{
@@ -130,7 +131,7 @@ func (s *LicenseService) parseClaims(claims *Claims) (*enterpriseAPI.License, er
}
if err := license.Valid(); err != nil {
- return nil, common.Errorf(common.Invalid, err)
+ return nil, common.WithError(common.Invalid, err)
}
return license, nil
@@ -144,10 +145,7 @@ func (s *LicenseService) readLicense() (string, error) {
})
if len(settings) == 0 {
- return "", common.Errorf(
- common.NotFound,
- fmt.Errorf("cannot find license with error %w", err),
- )
+ return "", common.Errorf(common.NotFound, "cannot find license with error %w", err)
}
return settings[0].Value, nil
diff --git a/plugin/db/clickhouse/dump.go b/plugin/db/clickhouse/dump.go
index 4659fd73cc..25fb4075d6 100644
--- a/plugin/db/clickhouse/dump.go
+++ b/plugin/db/clickhouse/dump.go
@@ -90,7 +90,7 @@ func dumpTxn(ctx context.Context, txn *sql.Tx, database string, out io.Writer) e
}
}
if !exist {
- return common.Errorf(common.NotFound, fmt.Errorf("database %s not found", database))
+ return common.Errorf(common.NotFound, "database %s not found", database)
}
dumpableDbNames = []string{database}
} else {
diff --git a/plugin/db/clickhouse/sync.go b/plugin/db/clickhouse/sync.go
index ca1103fec0..ba7f2ee719 100644
--- a/plugin/db/clickhouse/sync.go
+++ b/plugin/db/clickhouse/sync.go
@@ -196,7 +196,7 @@ func (driver *Driver) SyncDBSchema(ctx context.Context, databaseName string) (*d
&schema.Name,
); err != nil {
if err == sql.ErrNoRows {
- return nil, common.Errorf(common.NotFound, fmt.Errorf("database %q not found", databaseName))
+ return nil, common.Errorf(common.NotFound, "database %q not found", databaseName)
}
return nil, err
}
diff --git a/plugin/db/mysql/dump.go b/plugin/db/mysql/dump.go
index a036611577..cdd7d83044 100644
--- a/plugin/db/mysql/dump.go
+++ b/plugin/db/mysql/dump.go
@@ -11,11 +11,12 @@ import (
"strings"
"time"
+ "go.uber.org/zap"
+
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/common/log"
"github.com/bytebase/bytebase/plugin/db/util"
- "go.uber.org/zap"
)
// Dump and restore
@@ -189,7 +190,7 @@ func dumpTxn(ctx context.Context, txn *sql.Tx, database string, out io.Writer, s
}
}
if !exist {
- return common.Errorf(common.NotFound, fmt.Errorf("database %s not found", database))
+ return common.Errorf(common.NotFound, "database %s not found", database)
}
dumpableDbNames = []string{database}
} else {
diff --git a/plugin/db/mysql/restore.go b/plugin/db/mysql/restore.go
index e1de9ed518..4a67ede90c 100644
--- a/plugin/db/mysql/restore.go
+++ b/plugin/db/mysql/restore.go
@@ -24,13 +24,14 @@ import (
"strings"
"time"
+ "go.uber.org/zap"
+ "go.uber.org/zap/zapcore"
+
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/common/log"
"github.com/bytebase/bytebase/plugin/db/util"
"github.com/bytebase/bytebase/resources/mysqlutil"
- "go.uber.org/zap"
- "go.uber.org/zap/zapcore"
"github.com/blang/semver/v4"
)
@@ -861,7 +862,7 @@ func (driver *Driver) getBinlogEventPositionAtOrAfterTs(ctx context.Context, bin
}
if pos == 0 {
- return 0, common.Errorf(common.NotFound, fmt.Errorf("failed to find event position at or after targetTs %d", targetTs))
+ return 0, common.Errorf(common.NotFound, "failed to find event position at or after targetTs %d", targetTs)
}
return pos, nil
diff --git a/plugin/db/mysql/sync.go b/plugin/db/mysql/sync.go
index c12e8965f8..7d4efd95ad 100644
--- a/plugin/db/mysql/sync.go
+++ b/plugin/db/mysql/sync.go
@@ -375,7 +375,7 @@ func (driver *Driver) SyncDBSchema(ctx context.Context, databaseName string) (*d
&schema.CharacterSet,
&schema.Collation); err != nil {
if err == sql.ErrNoRows {
- return nil, common.Errorf(common.NotFound, fmt.Errorf("database %q not found", databaseName))
+ return nil, common.Errorf(common.NotFound, "database %q not found", databaseName)
}
return nil, err
}
diff --git a/plugin/db/pg/sync.go b/plugin/db/pg/sync.go
index b8055d2ff1..33fa4bb5b0 100644
--- a/plugin/db/pg/sync.go
+++ b/plugin/db/pg/sync.go
@@ -156,7 +156,7 @@ func (driver *Driver) SyncDBSchema(ctx context.Context, databaseName string) (*d
}
}
if !found {
- return nil, common.Errorf(common.NotFound, fmt.Errorf("database %q not found", databaseName))
+ return nil, common.Errorf(common.NotFound, "database %q not found", databaseName)
}
sqldb, err := driver.GetDBConnection(ctx, databaseName)
diff --git a/plugin/db/snowflake/sync.go b/plugin/db/snowflake/sync.go
index 2c4385080c..cb8c5425a5 100644
--- a/plugin/db/snowflake/sync.go
+++ b/plugin/db/snowflake/sync.go
@@ -85,7 +85,7 @@ func (driver *Driver) SyncDBSchema(ctx context.Context, databaseName string) (*d
}
}
if !found {
- return nil, common.Errorf(common.NotFound, fmt.Errorf("database %q not found", databaseName))
+ return nil, common.Errorf(common.NotFound, "database %q not found", databaseName)
}
tableList, viewList, err := driver.syncTableSchema(ctx, databaseName)
diff --git a/plugin/db/sqlite/sync.go b/plugin/db/sqlite/sync.go
index 08e44d938d..6df3999d58 100644
--- a/plugin/db/sqlite/sync.go
+++ b/plugin/db/sqlite/sync.go
@@ -77,7 +77,7 @@ func (driver *Driver) SyncDBSchema(ctx context.Context, databaseName string) (*d
}
}
if !found {
- return nil, common.Errorf(common.NotFound, fmt.Errorf("database %q not found", databaseName))
+ return nil, common.Errorf(common.NotFound, "database %q not found", databaseName)
}
sqldb, err := driver.GetDBConnection(ctx, databaseName)
diff --git a/plugin/db/util/driverutil.go b/plugin/db/util/driverutil.go
index 3056847326..ddc26dda1b 100644
--- a/plugin/db/util/driverutil.go
+++ b/plugin/db/util/driverutil.go
@@ -11,15 +11,16 @@ import (
"time"
"github.com/blang/semver/v4"
+ "go.uber.org/zap"
+
"github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/common/log"
"github.com/bytebase/bytebase/plugin/db"
- "go.uber.org/zap"
)
// FormatErrorWithQuery will format the error with failed query.
func FormatErrorWithQuery(err error, query string) error {
- return common.Errorf(common.DbExecutionError, fmt.Errorf("failed to execute query %q, error: %w", query, err))
+ return common.Errorf(common.DbExecutionError, "failed to execute query %q, error: %w", query, err)
}
// ApplyMultiStatements will apply the split statements from scanner.
@@ -210,8 +211,8 @@ func BeginMigration(ctx context.Context, executor MigrationExecutor, m *db.Migra
} else if len(list) > 0 {
switch list[0].Status {
case db.Done:
- return int64(list[0].ID), common.Errorf(common.MigrationAlreadyApplied,
- fmt.Errorf("database %q has already applied version %s", m.Database, m.Version))
+ return int64(list[0].ID),
+ common.Errorf(common.MigrationAlreadyApplied, "database %q has already applied version %s", m.Database, m.Version)
case db.Pending:
err := fmt.Errorf("database %q version %s migration is already in progress", m.Database, m.Version)
log.Debug(err.Error())
@@ -219,7 +220,7 @@ func BeginMigration(ctx context.Context, executor MigrationExecutor, m *db.Migra
if m.Force {
return int64(list[0].ID), nil
}
- return -1, common.Errorf(common.MigrationPending, err)
+ return -1, common.WithError(common.MigrationPending, err)
case db.Failed:
err := fmt.Errorf("database %q version %s migration has failed, please check your database to make sure things are fine and then start a new migration using a new version ", m.Database, m.Version)
log.Debug(err.Error())
@@ -227,7 +228,7 @@ func BeginMigration(ctx context.Context, executor MigrationExecutor, m *db.Migra
if m.Force {
return int64(list[0].ID), nil
}
- return -1, common.Errorf(common.MigrationFailed, err)
+ return -1, common.WithError(common.MigrationFailed, err)
}
}
@@ -252,7 +253,7 @@ func BeginMigration(ctx context.Context, executor MigrationExecutor, m *db.Migra
return -1, err
} else if version != nil && len(*version) > 0 && *version >= m.Version {
// len(*version) > 0 is used because Clickhouse will always return non-nil version with empty string.
- return -1, common.Errorf(common.MigrationOutOfOrder, fmt.Errorf("database %q has already applied version %s which >= %s", m.Database, *version, m.Version))
+ return -1, common.Errorf(common.MigrationOutOfOrder, "database %q has already applied version %s which >= %s", m.Database, *version, m.Version)
}
// Phase 2 - Record migration history as PENDING.
diff --git a/plugin/vcs/github/github.go b/plugin/vcs/github/github.go
index c1bd34eb70..3654b92939 100644
--- a/plugin/vcs/github/github.go
+++ b/plugin/vcs/github/github.go
@@ -167,7 +167,7 @@ func (p *Provider) fetchUserInfo(ctx context.Context, oauthCtx common.OauthConte
}
if code == http.StatusNotFound {
- return nil, common.Errorf(common.NotFound, fmt.Errorf("failed to read user info from URL %s", url))
+ return nil, common.Errorf(common.NotFound, "failed to read user info from URL %s", url)
} else if code >= 300 {
return nil, fmt.Errorf("failed to read user info from URL %s, status code: %d, body: %s", url, code, body)
}
@@ -228,7 +228,7 @@ func (p *Provider) FetchCommitByID(ctx context.Context, oauthCtx common.OauthCon
}
if code == http.StatusNotFound {
- return nil, common.Errorf(common.NotFound, fmt.Errorf("failed to fetch commit data from URL %s", url))
+ return nil, common.Errorf(common.NotFound, "failed to fetch commit data from URL %s", url)
} else if code >= 300 {
return nil, fmt.Errorf("failed to fetch commit data from URL %s, status code: %d, body: %s", url, code, body)
}
@@ -344,7 +344,7 @@ func (p *Provider) fetchPaginatedRepositoryCollaborators(ctx context.Context, oa
}
if code == http.StatusNotFound {
- return nil, false, common.Errorf(common.NotFound, fmt.Errorf("failed to fetch repository collaborators from URL %s", url))
+ return nil, false, common.Errorf(common.NotFound, "failed to fetch repository collaborators from URL %s", url)
} else if code >= 300 {
return nil, false,
fmt.Errorf("failed to read repository collaborators from URL %s, status code: %d, body: %s",
@@ -482,7 +482,7 @@ func (p *Provider) fetchPaginatedRepositoryList(ctx context.Context, oauthCtx co
}
if code == http.StatusNotFound {
- return nil, false, common.Errorf(common.NotFound, fmt.Errorf("failed to fetch repository list from URL %s", url))
+ return nil, false, common.Errorf(common.NotFound, "failed to fetch repository list from URL %s", url)
} else if code >= 300 {
return nil, false,
fmt.Errorf("failed to fetch repository list from URL %s, status code: %d, body: %s",
@@ -532,7 +532,7 @@ func (p *Provider) FetchRepositoryFileList(ctx context.Context, oauthCtx common.
}
if code == http.StatusNotFound {
- return nil, common.Errorf(common.NotFound, fmt.Errorf("failed to fetch repository file list from URL %s", url))
+ return nil, common.Errorf(common.NotFound, "failed to fetch repository file list from URL %s", url)
} else if code >= 300 {
return nil,
fmt.Errorf("failed to fetch repository file list from URL %s, status code: %d, body: %s",
@@ -604,7 +604,7 @@ func (p *Provider) CreateFile(ctx context.Context, oauthCtx common.OauthContext,
}
if code == http.StatusNotFound {
- return common.Errorf(common.NotFound, fmt.Errorf("failed to create/update file through URL %s", url))
+ return common.Errorf(common.NotFound, "failed to create/update file through URL %s", url)
} else if code >= 300 {
return fmt.Errorf("failed to create/update file through URL %s, status code: %d, body: %s",
url,
@@ -672,7 +672,7 @@ func (p *Provider) readFile(ctx context.Context, oauthCtx common.OauthContext, r
}
if code == http.StatusNotFound {
- return nil, common.Errorf(common.NotFound, fmt.Errorf("failed to read file from URL %s", url))
+ return nil, common.Errorf(common.NotFound, "failed to read file from URL %s", url)
} else if code >= 300 {
return nil,
fmt.Errorf("failed to read file from URL %s, status code: %d, body: %s",
@@ -728,7 +728,7 @@ func (p *Provider) CreateWebhook(ctx context.Context, oauthCtx common.OauthConte
}
if code == http.StatusNotFound {
- return "", common.Errorf(common.NotFound, fmt.Errorf("failed to create webhook through URL %s", url))
+ return "", common.Errorf(common.NotFound, "failed to create webhook through URL %s", url)
} else if code >= 300 {
return "",
fmt.Errorf("failed to create webhook through URL %s, status code: %d, body: %s",
@@ -770,7 +770,7 @@ func (p *Provider) PatchWebhook(ctx context.Context, oauthCtx common.OauthContex
}
if code == http.StatusNotFound {
- return common.Errorf(common.NotFound, fmt.Errorf("failed to patch webhook through URL %s", url))
+ return common.Errorf(common.NotFound, "failed to patch webhook through URL %s", url)
} else if code >= 300 {
return fmt.Errorf("failed to patch webhook through URL %s, status code: %d, body: %s",
url,
diff --git a/plugin/vcs/gitlab/gitlab.go b/plugin/vcs/gitlab/gitlab.go
index bcf8cc67f3..c48922e09c 100644
--- a/plugin/vcs/gitlab/gitlab.go
+++ b/plugin/vcs/gitlab/gitlab.go
@@ -315,7 +315,7 @@ func (p *Provider) fetchPaginatedRepositoryList(ctx context.Context, oauthCtx co
}
if code == http.StatusNotFound {
- return nil, false, common.Errorf(common.NotFound, fmt.Errorf("failed to fetch repository list from URL %s", url))
+ return nil, false, common.Errorf(common.NotFound, "failed to fetch repository list from URL %s", url)
} else if code >= 300 {
return nil, false,
fmt.Errorf("failed to fetch repository list from URL %s, status code: %d, body: %s",
@@ -360,7 +360,7 @@ func (p *Provider) fetchUserInfo(ctx context.Context, oauthCtx common.OauthConte
}
if code == http.StatusNotFound {
- return nil, common.Errorf(common.NotFound, fmt.Errorf("failed to read user info from URL %s", url))
+ return nil, common.Errorf(common.NotFound, "failed to read user info from URL %s", url)
} else if code >= 300 {
return nil, fmt.Errorf("failed to read user info from URL %s, status code: %d, body: %s",
url,
@@ -403,7 +403,7 @@ func (p *Provider) FetchCommitByID(ctx context.Context, oauthCtx common.OauthCon
return nil, errors.Wrap(err, "GET")
}
if code == http.StatusNotFound {
- return nil, common.Errorf(common.NotFound, fmt.Errorf("failed to fetch commit data from URL %s", url))
+ return nil, common.Errorf(common.NotFound, "failed to fetch commit data from URL %s", url)
} else if code >= 300 {
return nil, fmt.Errorf("failed to fetch commit data from URL %s, status code: %d, body: %s",
url,
@@ -544,7 +544,7 @@ func (p *Provider) fetchPaginatedRepositoryActiveMemberList(ctx context.Context,
}
if code == http.StatusNotFound {
- return nil, false, common.Errorf(common.NotFound, fmt.Errorf("failed to fetch repository members from URL %s", url))
+ return nil, false, common.Errorf(common.NotFound, "failed to fetch repository members from URL %s", url)
} else if code >= 300 {
return nil, false,
fmt.Errorf("failed to fetch repository members from URL %s, status code: %d, body: %s",
@@ -624,7 +624,7 @@ func (p *Provider) fetchPaginatedRepositoryFileList(ctx context.Context, oauthCt
}
if code == http.StatusNotFound {
- return nil, false, common.Errorf(common.NotFound, fmt.Errorf("failed to fetch repository file list from URL %s", url))
+ return nil, false, common.Errorf(common.NotFound, "failed to fetch repository file list from URL %s", url)
} else if code >= 300 {
return nil, false,
fmt.Errorf("failed to fetch repository file list from URL %s, status code: %d, body: %s",
@@ -682,7 +682,7 @@ func (p *Provider) CreateFile(ctx context.Context, oauthCtx common.OauthContext,
}
if code == http.StatusNotFound {
- return common.Errorf(common.NotFound, fmt.Errorf("failed to create file through URL %s", url))
+ return common.Errorf(common.NotFound, "failed to create file through URL %s", url)
} else if code >= 300 {
return fmt.Errorf("failed to create file through URL %s, status code: %d, body: %s",
url,
@@ -731,7 +731,7 @@ func (p *Provider) OverwriteFile(ctx context.Context, oauthCtx common.OauthConte
}
if code == http.StatusNotFound {
- return common.Errorf(common.NotFound, fmt.Errorf("failed to overwrite file through URL %s", url))
+ return common.Errorf(common.NotFound, "failed to overwrite file through URL %s", url)
} else if code >= 300 {
return fmt.Errorf("failed to overwrite file through URL %s, status code: %d, body: %s",
url,
@@ -796,7 +796,7 @@ func (p *Provider) CreateWebhook(ctx context.Context, oauthCtx common.OauthConte
}
if code == http.StatusNotFound {
- return "", common.Errorf(common.NotFound, fmt.Errorf("failed to create webhook through URL %s", url))
+ return "", common.Errorf(common.NotFound, "failed to create webhook through URL %s", url)
} else if code >= 300 {
reason := fmt.Sprintf("failed to create webhook through URL %s, status code: %d, body: %s",
url,
@@ -845,7 +845,7 @@ func (p *Provider) PatchWebhook(ctx context.Context, oauthCtx common.OauthContex
}
if code == http.StatusNotFound {
- return common.Errorf(common.NotFound, fmt.Errorf("failed to patch webhook through URL %s", url))
+ return common.Errorf(common.NotFound, "failed to patch webhook through URL %s", url)
} else if code >= 300 {
return fmt.Errorf("failed to patch webhook through URL %s, status code: %d, body: %s",
url,
@@ -918,7 +918,7 @@ func (p *Provider) readFile(ctx context.Context, oauthCtx common.OauthContext, i
}
if code == http.StatusNotFound {
- return nil, common.Errorf(common.NotFound, fmt.Errorf("failed to read file from URL %s", url))
+ return nil, common.Errorf(common.NotFound, "failed to read file from URL %s", url)
} else if code >= 300 {
return nil,
fmt.Errorf("failed to read file from URL %s, status code: %d, body: %s",
diff --git a/server/database.go b/server/database.go
index ef80f0a241..4475f9c2f6 100644
--- a/server/database.go
+++ b/server/database.go
@@ -853,7 +853,7 @@ func getAdminDatabaseDriver(ctx context.Context, instance *api.Instance, databas
func getConnectionConfig(instance *api.Instance, databaseName string) (db.ConnectionConfig, error) {
adminDataSource := api.DataSourceFromInstanceWithType(instance, api.Admin)
if adminDataSource == nil {
- return db.ConnectionConfig{}, common.Errorf(common.Internal, fmt.Errorf("admin data source not found for instance %d", instance.ID))
+ return db.ConnectionConfig{}, common.Errorf(common.Internal, "admin data source not found for instance %d", instance.ID)
}
return db.ConnectionConfig{
@@ -879,7 +879,7 @@ func tryGetReadOnlyDatabaseDriver(ctx context.Context, instance *api.Instance, d
dataSource = api.DataSourceFromInstanceWithType(instance, api.Admin)
}
if dataSource == nil {
- return nil, common.Errorf(common.Internal, fmt.Errorf("data source not found for instance %d", instance.ID))
+ return nil, common.Errorf(common.Internal, "data source not found for instance %d", instance.ID)
}
driver, err := getDatabaseDriver(
@@ -922,7 +922,7 @@ func getDatabaseDriver(ctx context.Context, engine db.Type, driverConfig db.Driv
connCtx,
)
if err != nil {
- return nil, common.Errorf(common.DbConnectionFailure, fmt.Errorf("failed to connect database at %s:%s with user %q, error: %w", connectionConfig.Host, connectionConfig.Port, connectionConfig.Username, err))
+ return nil, common.Errorf(common.DbConnectionFailure, "failed to connect database at %s:%s with user %q, error: %w", connectionConfig.Host, connectionConfig.Port, connectionConfig.Username, err)
}
return driver, nil
}
@@ -946,20 +946,20 @@ func validateDatabaseLabelList(labelList []*api.DatabaseLabel, labelKeyList []*a
}
labelKey, ok := keyValueList[label.Key]
if !ok {
- return common.Errorf(common.Invalid, fmt.Errorf("invalid database label key: %v", label.Key))
+ return common.Errorf(common.Invalid, "invalid database label key: %v", label.Key)
}
_, ok = labelKey[label.Value]
if !ok {
- return common.Errorf(common.Invalid, fmt.Errorf("invalid database label value %v for key %v", label.Value, label.Key))
+ return common.Errorf(common.Invalid, "invalid database label value %v for key %v", label.Value, label.Key)
}
}
// Environment label must exist and is immutable.
if environmentValue == nil {
- return common.Errorf(common.NotFound, fmt.Errorf("database label key %v not found", api.EnvironmentKeyName))
+ return common.Errorf(common.NotFound, "database label key %v not found", api.EnvironmentKeyName)
}
if environmentName != *environmentValue {
- return common.Errorf(common.Invalid, fmt.Errorf("cannot mutate database label key %v from %v to %v", api.EnvironmentKeyName, environmentName, *environmentValue))
+ return common.Errorf(common.Invalid, "cannot mutate database label key %v from %v to %v", api.EnvironmentKeyName, environmentName, *environmentValue)
}
return nil
diff --git a/server/task_check_executor_database_connect.go b/server/task_check_executor_database_connect.go
index 0c69816aa2..598850c880 100644
--- a/server/task_check_executor_database_connect.go
+++ b/server/task_check_executor_database_connect.go
@@ -21,7 +21,7 @@ type TaskCheckDatabaseConnectExecutor struct {
func (exec *TaskCheckDatabaseConnectExecutor) Run(ctx context.Context, server *Server, taskCheckRun *api.TaskCheckRun) (result []api.TaskCheckResult, err error) {
task, err := server.store.GetTaskByID(ctx, taskCheckRun.TaskID)
if err != nil {
- return []api.TaskCheckResult{}, common.Errorf(common.Internal, err)
+ return []api.TaskCheckResult{}, common.WithError(common.Internal, err)
}
if task == nil {
return []api.TaskCheckResult{
@@ -37,10 +37,10 @@ func (exec *TaskCheckDatabaseConnectExecutor) Run(ctx context.Context, server *S
database, err := server.store.GetDatabase(ctx, &api.DatabaseFind{ID: task.DatabaseID})
if err != nil {
- return []api.TaskCheckResult{}, common.Errorf(common.Internal, err)
+ return []api.TaskCheckResult{}, common.WithError(common.Internal, err)
}
if database == nil {
- return []api.TaskCheckResult{}, common.Errorf(common.Internal, fmt.Errorf("database ID not found %v", task.DatabaseID))
+ return []api.TaskCheckResult{}, common.Errorf(common.Internal, "database ID not found %v", task.DatabaseID)
}
driver, err := getAdminDatabaseDriver(ctx, database.Instance, database.Name, server.pgInstanceDir)
diff --git a/server/task_check_executor_ghost_sync.go b/server/task_check_executor_ghost_sync.go
index 6db1a553ea..2a4c2f1f40 100644
--- a/server/task_check_executor_ghost_sync.go
+++ b/server/task_check_executor_ghost_sync.go
@@ -5,9 +5,10 @@ import (
"encoding/json"
"fmt"
+ "github.com/github/gh-ost/go/logic"
+
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
- "github.com/github/gh-ost/go/logic"
)
// NewTaskCheckGhostSyncExecutor creates a task check gh-ost sync executor.
@@ -44,7 +45,7 @@ func (exec *TaskCheckGhostSyncExecutor) Run(ctx context.Context, server *Server,
}()
task, err := server.store.GetTaskByID(ctx, taskCheckRun.TaskID)
if err != nil {
- return []api.TaskCheckResult{}, common.Errorf(common.Internal, err)
+ return []api.TaskCheckResult{}, common.WithError(common.Internal, err)
}
if task == nil {
return []api.TaskCheckResult{
@@ -60,28 +61,28 @@ func (exec *TaskCheckGhostSyncExecutor) Run(ctx context.Context, server *Server,
instance := task.Instance
if instance == nil {
- return []api.TaskCheckResult{}, common.Errorf(common.Internal, fmt.Errorf("instance ID not found %v", task.InstanceID))
+ return []api.TaskCheckResult{}, common.Errorf(common.Internal, "instance ID not found %v", task.InstanceID)
}
database := task.Database
if database == nil {
- return []api.TaskCheckResult{}, common.Errorf(common.Internal, fmt.Errorf("database ID not found %v", task.DatabaseID))
+ return []api.TaskCheckResult{}, common.Errorf(common.Internal, "database ID not found %v", task.DatabaseID)
}
adminDataSource := api.DataSourceFromInstanceWithType(instance, api.Admin)
if adminDataSource == nil {
- return []api.TaskCheckResult{}, common.Errorf(common.Internal, fmt.Errorf("admin data source not found for instance %d", instance.ID))
+ return []api.TaskCheckResult{}, common.Errorf(common.Internal, "admin data source not found for instance %d", instance.ID)
}
payload := &api.TaskDatabaseSchemaUpdateGhostSyncPayload{}
if err := json.Unmarshal([]byte(task.Payload), payload); err != nil {
- return []api.TaskCheckResult{}, common.Errorf(common.Internal, fmt.Errorf("invalid database schema update gh-ost sync payload: %w", err))
+ return []api.TaskCheckResult{}, common.Errorf(common.Internal, "invalid database schema update gh-ost sync payload: %w", err)
}
databaseName := database.Name
tableName, err := getTableNameFromStatement(payload.Statement)
if err != nil {
- return []api.TaskCheckResult{}, common.Errorf(common.Internal, fmt.Errorf("failed to parse table name from statement, statement: %v, error: %w", payload.Statement, err))
+ return []api.TaskCheckResult{}, common.Errorf(common.Internal, "failed to parse table name from statement, statement: %v, error: %w", payload.Statement, err)
}
migrationContext, err := newMigrationContext(ghostConfig{
@@ -101,7 +102,7 @@ func (exec *TaskCheckGhostSyncExecutor) Run(ctx context.Context, server *Server,
serverID: 20000000 + uint(taskCheckRun.ID),
})
if err != nil {
- return []api.TaskCheckResult{}, common.Errorf(common.Internal, fmt.Errorf("failed to create migration context, error: %w", err))
+ return []api.TaskCheckResult{}, common.Errorf(common.Internal, "failed to create migration context, error: %w", err)
}
migrator := logic.NewMigrator(migrationContext)
diff --git a/server/task_check_executor_migration_schema.go b/server/task_check_executor_migration_schema.go
index 0704465a5a..f6a2200f91 100644
--- a/server/task_check_executor_migration_schema.go
+++ b/server/task_check_executor_migration_schema.go
@@ -21,7 +21,7 @@ type TaskCheckMigrationSchemaExecutor struct {
func (exec *TaskCheckMigrationSchemaExecutor) Run(ctx context.Context, server *Server, taskCheckRun *api.TaskCheckRun) (result []api.TaskCheckResult, err error) {
task, err := server.store.GetTaskByID(ctx, taskCheckRun.TaskID)
if err != nil {
- return []api.TaskCheckResult{}, common.Errorf(common.Internal, err)
+ return []api.TaskCheckResult{}, common.WithError(common.Internal, err)
}
if task == nil {
return []api.TaskCheckResult{
diff --git a/server/task_check_executor_statement_advisor_composite.go b/server/task_check_executor_statement_advisor_composite.go
index 3e6c917c09..461fa11d8d 100644
--- a/server/task_check_executor_statement_advisor_composite.go
+++ b/server/task_check_executor_statement_advisor_composite.go
@@ -3,7 +3,6 @@ package server
import (
"context"
"encoding/json"
- "fmt"
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
@@ -29,15 +28,15 @@ type TaskCheckStatementAdvisorCompositeExecutor struct {
// Run will run the task check statement advisor composite executor once, and run its sub-advisor one-by-one.
func (exec *TaskCheckStatementAdvisorCompositeExecutor) Run(ctx context.Context, server *Server, taskCheckRun *api.TaskCheckRun) (result []api.TaskCheckResult, err error) {
if taskCheckRun.Type != api.TaskCheckDatabaseStatementAdvise {
- return nil, common.Errorf(common.Invalid, fmt.Errorf("invalid check statement advisor composite type: %v", taskCheckRun.Type))
+ return nil, common.Errorf(common.Invalid, "invalid check statement advisor composite type: %v", taskCheckRun.Type)
}
if !server.feature(api.FeatureSQLReviewPolicy) {
- return nil, common.Errorf(common.NotAuthorized, fmt.Errorf(api.FeatureSQLReviewPolicy.AccessErrorMessage()))
+ return nil, common.Errorf(common.NotAuthorized, api.FeatureSQLReviewPolicy.AccessErrorMessage())
}
payload := &api.TaskCheckDatabaseStatementAdvisePayload{}
if err := json.Unmarshal([]byte(taskCheckRun.Payload), payload); err != nil {
- return nil, common.Errorf(common.Invalid, fmt.Errorf("invalid check statement advise payload: %w", err))
+ return nil, common.Errorf(common.Invalid, "invalid check statement advise payload: %w", err)
}
policy, err := server.store.GetNormalSchemaReviewPolicy(ctx, &api.PolicyFind{ID: &payload.PolicyID})
@@ -53,12 +52,12 @@ func (exec *TaskCheckStatementAdvisorCompositeExecutor) Run(ctx context.Context,
},
}, nil
}
- return nil, common.Errorf(common.Internal, fmt.Errorf("failed to get schema review policy: %w", err))
+ return nil, common.Errorf(common.Internal, "failed to get schema review policy: %w", err)
}
task, err := server.store.GetTaskByID(ctx, taskCheckRun.TaskID)
if err != nil {
- return nil, common.Errorf(common.Internal, fmt.Errorf("failed to get task by id: %w", err))
+ return nil, common.Errorf(common.Internal, "failed to get task by id: %w", err)
}
catalog := store.NewCatalog(task.DatabaseID, server.store, payload.DbType)
diff --git a/server/task_check_executor_statement_advisor_simple.go b/server/task_check_executor_statement_advisor_simple.go
index 7aa7e920c2..1755f44de8 100644
--- a/server/task_check_executor_statement_advisor_simple.go
+++ b/server/task_check_executor_statement_advisor_simple.go
@@ -3,7 +3,6 @@ package server
import (
"context"
"encoding/json"
- "fmt"
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
@@ -24,7 +23,7 @@ type TaskCheckStatementAdvisorSimpleExecutor struct {
func (exec *TaskCheckStatementAdvisorSimpleExecutor) Run(_ context.Context, _ *Server, taskCheckRun *api.TaskCheckRun) (result []api.TaskCheckResult, err error) {
payload := &api.TaskCheckDatabaseStatementAdvisePayload{}
if err := json.Unmarshal([]byte(taskCheckRun.Payload), payload); err != nil {
- return nil, common.Errorf(common.Invalid, fmt.Errorf("invalid check statement advise payload: %w", err))
+ return nil, common.Errorf(common.Invalid, "invalid check statement advise payload: %w", err)
}
var advisorType advisor.Type
@@ -38,7 +37,7 @@ func (exec *TaskCheckStatementAdvisorSimpleExecutor) Run(_ context.Context, _ *S
case db.Postgres:
advisorType = advisor.PostgreSQLSyntax
default:
- return nil, common.Errorf(common.Invalid, fmt.Errorf("invalid database type: %s for syntax statement advisor", payload.DbType))
+ return nil, common.Errorf(common.Invalid, "invalid database type: %s for syntax statement advisor", payload.DbType)
}
}
@@ -57,7 +56,7 @@ func (exec *TaskCheckStatementAdvisorSimpleExecutor) Run(_ context.Context, _ *S
payload.Statement,
)
if err != nil {
- return nil, common.Errorf(common.Internal, fmt.Errorf("failed to check statement: %w", err))
+ return nil, common.Errorf(common.Internal, "failed to check statement: %w", err)
}
result = []api.TaskCheckResult{}
diff --git a/server/task_check_executor_timing.go b/server/task_check_executor_timing.go
index cac75dd927..1d0488c109 100644
--- a/server/task_check_executor_timing.go
+++ b/server/task_check_executor_timing.go
@@ -25,7 +25,7 @@ const dataFormat = "2006-01-02 15:04:05"
func (exec *TaskCheckTimingExecutor) Run(_ context.Context, _ *Server, taskCheckRun *api.TaskCheckRun) (result []api.TaskCheckResult, err error) {
payload := &api.TaskCheckEarliestAllowedTimePayload{}
if err := json.Unmarshal([]byte(taskCheckRun.Payload), payload); err != nil {
- return []api.TaskCheckResult{}, common.Errorf(common.Invalid, fmt.Errorf("invalid check timing payload: %w", err))
+ return []api.TaskCheckResult{}, common.Errorf(common.Invalid, "invalid check timing payload: %w", err)
}
if payload.EarliestAllowedTs == 0 {
diff --git a/server/task_executor.go b/server/task_executor.go
index 745b293719..7ec30d8aa0 100644
--- a/server/task_executor.go
+++ b/server/task_executor.go
@@ -152,7 +152,7 @@ func executeMigration(ctx context.Context, pgInstanceDir string, task *api.Task,
return 0, "", fmt.Errorf("failed to check migration setup for instance %q: %w", task.Instance.Name, err)
}
if setup {
- return 0, "", common.Errorf(common.MigrationSchemaMissing, fmt.Errorf("missing migration schema for instance %q", task.Instance.Name))
+ return 0, "", common.Errorf(common.MigrationSchemaMissing, "missing migration schema for instance %q", task.Instance.Name)
}
migrationID, schema, err = driver.ExecuteMigration(ctx, mi, statement)
diff --git a/server/task_executor_schema_update_ghost_cutover.go b/server/task_executor_schema_update_ghost_cutover.go
index 0a1cd22da0..8bba584335 100644
--- a/server/task_executor_schema_update_ghost_cutover.go
+++ b/server/task_executor_schema_update_ghost_cutover.go
@@ -10,13 +10,14 @@ import (
"sync/atomic"
"time"
+ "go.uber.org/zap"
+
"github.com/bytebase/bytebase/api"
"github.com/bytebase/bytebase/common"
"github.com/bytebase/bytebase/common/log"
"github.com/bytebase/bytebase/plugin/db"
"github.com/bytebase/bytebase/plugin/db/util"
vcsPlugin "github.com/bytebase/bytebase/plugin/vcs"
- "go.uber.org/zap"
)
// NewSchemaUpdateGhostCutoverTaskExecutor creates a schema update (gh-ost) cutover task executor.
@@ -76,7 +77,7 @@ func cutover(ctx context.Context, server *Server, task *api.Task, statement, sch
return -1, "", fmt.Errorf("failed to check migration setup for instance %q: %w", task.Instance.Name, err)
}
if needsSetup {
- return -1, "", common.Errorf(common.MigrationSchemaMissing, fmt.Errorf("missing migration schema for instance %q", task.Instance.Name))
+ return -1, "", common.Errorf(common.MigrationSchemaMissing, "missing migration schema for instance %q", task.Instance.Name)
}
executor := driver.(util.MigrationExecutor)
diff --git a/server/task_executor_schema_update_ghost_sync.go b/server/task_executor_schema_update_ghost_sync.go
index bad6728dc4..183c69a256 100644
--- a/server/task_executor_schema_update_ghost_sync.go
+++ b/server/task_executor_schema_update_ghost_sync.go
@@ -9,13 +9,14 @@ import (
"sync/atomic"
"time"
- "github.com/bytebase/bytebase/api"
- "github.com/bytebase/bytebase/common"
- "github.com/bytebase/bytebase/common/log"
"github.com/github/gh-ost/go/base"
"github.com/github/gh-ost/go/logic"
ghostsql "github.com/github/gh-ost/go/sql"
"go.uber.org/zap"
+
+ "github.com/bytebase/bytebase/api"
+ "github.com/bytebase/bytebase/common"
+ "github.com/bytebase/bytebase/common/log"
)
// NewSchemaUpdateGhostSyncTaskExecutor creates a schema update (gh-ost) sync task executor.
@@ -192,7 +193,7 @@ func executeGhost(task *api.Task, statement string, syncDone chan<- struct{}) er
adminDataSource := api.DataSourceFromInstanceWithType(instance, api.Admin)
if adminDataSource == nil {
- return common.Errorf(common.Internal, fmt.Errorf("admin data source not found for instance %d", instance.ID))
+ return common.Errorf(common.Internal, "admin data source not found for instance %d", instance.ID)
}
migrationContext, err := newMigrationContext(ghostConfig{
diff --git a/store/label.go b/store/label.go
index b8c2766538..32a8d9f2d1 100644
--- a/store/label.go
+++ b/store/label.go
@@ -335,7 +335,7 @@ func (s *Store) findLabelKeyImpl(ctx context.Context, tx *sql.Tx, find *api.Labe
}
labelKey, ok := keymap[key]
if !ok {
- return nil, common.Errorf(common.Internal, fmt.Errorf("label value doesn't have a label key, key %q, value %q", key, value))
+ return nil, common.Errorf(common.Internal, "label value doesn't have a label key, key %q, value %q", key, value)
}
labelKey.ValueList = append(labelKey.ValueList, value)
}
@@ -372,7 +372,7 @@ func (s *Store) patchLabelKeyRaw(ctx context.Context, patch *api.LabelKeyPatch)
}
}
if labelKeyRaw == nil {
- return nil, common.Errorf(common.NotFound, fmt.Errorf("label key not found with ID %v", patch.ID))
+ return nil, common.Errorf(common.NotFound, "label key not found with ID %v", patch.ID)
}
// Generate label value upserts.
diff --git a/store/pg_engine.go b/store/pg_engine.go
index 310d77b674..7f380f97f2 100644
--- a/store/pg_engine.go
+++ b/store/pg_engine.go
@@ -694,55 +694,55 @@ func FormatError(err error) error {
if strings.Contains(err.Error(), "unique constraint") {
switch {
case strings.Contains(err.Error(), "idx_principal_unique_email"):
- return common.Errorf(common.Conflict, fmt.Errorf("email already exists"))
+ return common.Errorf(common.Conflict, "email already exists")
case strings.Contains(err.Error(), "idx_setting_unique_name"):
- return common.Errorf(common.Conflict, fmt.Errorf("setting name already exists"))
+ return common.Errorf(common.Conflict, "setting name already exists")
case strings.Contains(err.Error(), "idx_member_unique_principal_id"):
- return common.Errorf(common.Conflict, fmt.Errorf("member already exists"))
+ return common.Errorf(common.Conflict, "member already exists")
case strings.Contains(err.Error(), "idx_environment_unique_name"):
- return common.Errorf(common.Conflict, fmt.Errorf("environment name already exists"))
+ return common.Errorf(common.Conflict, "environment name already exists")
case strings.Contains(err.Error(), "idx_policy_unique_environment_id_type"):
- return common.Errorf(common.Conflict, fmt.Errorf("policy environment and type already exists"))
+ return common.Errorf(common.Conflict, "policy environment and type already exists")
case strings.Contains(err.Error(), "idx_project_unique_key"):
- return common.Errorf(common.Conflict, fmt.Errorf("project key already exists"))
+ return common.Errorf(common.Conflict, "project key already exists")
case strings.Contains(err.Error(), "idx_project_member_unique_project_id_role_provider_principal_id"):
- return common.Errorf(common.Conflict, fmt.Errorf("project member already exists"))
+ return common.Errorf(common.Conflict, "project member already exists")
case strings.Contains(err.Error(), "idx_project_webhook_unique_project_id_url"):
- return common.Errorf(common.Conflict, fmt.Errorf("webhook url already exists"))
+ return common.Errorf(common.Conflict, "webhook url already exists")
case strings.Contains(err.Error(), "idx_instance_user_unique_instance_id_name"):
- return common.Errorf(common.Conflict, fmt.Errorf("instance id and name already exists"))
+ return common.Errorf(common.Conflict, "instance id and name already exists")
case strings.Contains(err.Error(), "idx_db_unique_instance_id_name"):
- return common.Errorf(common.Conflict, fmt.Errorf("database name already exists"))
+ return common.Errorf(common.Conflict, "database name already exists")
case strings.Contains(err.Error(), "idx_tbl_unique_database_id_name"):
- return common.Errorf(common.Conflict, fmt.Errorf("database id and name already exists"))
+ return common.Errorf(common.Conflict, "database id and name already exists")
case strings.Contains(err.Error(), "idx_col_unique_database_id_table_id_name"):
- return common.Errorf(common.Conflict, fmt.Errorf("database id, table id and name already exists"))
+ return common.Errorf(common.Conflict, "database id, table id and name already exists")
case strings.Contains(err.Error(), "idx_idx_unique_database_id_table_id_name_expression"):
- return common.Errorf(common.Conflict, fmt.Errorf("database id, table id, name and expression already exists"))
+ return common.Errorf(common.Conflict, "database id, table id, name and expression already exists")
case strings.Contains(err.Error(), "idx_vw_unique_database_id_name"):
- return common.Errorf(common.Conflict, fmt.Errorf("database id and name already exists"))
+ return common.Errorf(common.Conflict, "database id and name already exists")
case strings.Contains(err.Error(), "idx_data_source_unique_database_id_name"):
- return common.Errorf(common.Conflict, fmt.Errorf("data source name already exists"))
+ return common.Errorf(common.Conflict, "data source name already exists")
case strings.Contains(err.Error(), "idx_backup_unique_database_id_name"):
- return common.Errorf(common.Conflict, fmt.Errorf("backup name already exists"))
+ return common.Errorf(common.Conflict, "backup name already exists")
case strings.Contains(err.Error(), "idx_backup_setting_unique_database_id"):
- return common.Errorf(common.Conflict, fmt.Errorf("database id already exists"))
+ return common.Errorf(common.Conflict, "database id already exists")
case strings.Contains(err.Error(), "idx_bookmark_unique_creator_id_link"):
- return common.Errorf(common.Conflict, fmt.Errorf("bookmark already exists"))
+ return common.Errorf(common.Conflict, "bookmark already exists")
case strings.Contains(err.Error(), "idx_repository_unique_project_id"):
- return common.Errorf(common.Conflict, fmt.Errorf("project has already linked repository"))
+ return common.Errorf(common.Conflict, "project has already linked repository")
case strings.Contains(err.Error(), "idx_repository_unique_webhook_endpoint_id"):
- return common.Errorf(common.Conflict, fmt.Errorf("webhook endpoint already exists"))
+ return common.Errorf(common.Conflict, "webhook endpoint already exists")
case strings.Contains(err.Error(), "idx_label_key_unique_key"):
- return common.Errorf(common.Conflict, fmt.Errorf("label key already exists"))
+ return common.Errorf(common.Conflict, "label key already exists")
case strings.Contains(err.Error(), "idx_label_value_unique_key_value"):
- return common.Errorf(common.Conflict, fmt.Errorf("label key value already exists"))
+ return common.Errorf(common.Conflict, "label key value already exists")
case strings.Contains(err.Error(), "idx_db_label_unique_database_id_key"):
- return common.Errorf(common.Conflict, fmt.Errorf("database id and key already exists"))
+ return common.Errorf(common.Conflict, "database id and key already exists")
case strings.Contains(err.Error(), "idx_deployment_config_unique_project_id"):
- return common.Errorf(common.Conflict, fmt.Errorf("project deployment configuration already exists"))
+ return common.Errorf(common.Conflict, "project deployment configuration already exists")
case strings.Contains(err.Error(), "issue_subscriber_pkey"):
- return common.Errorf(common.Conflict, fmt.Errorf("issue subscriber already exists"))
+ return common.Errorf(common.Conflict, "issue subscriber already exists")
}
}
return err