Skip to content

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

For our error class, wrap the original error instead of the error message

天舟0ac95b35e3c7
diff --git a/common/error.go b/common/error.go
index 9aa58cb4e6..dc94f0f848 100644
--- a/common/error.go
+++ b/common/error.go
@@ -28,20 +28,20 @@ const (
// unwrapped by the caller to extract out the code & message.
//
// Any non-application error (such as a disk error) should be reported as an
-// EINTERNAL error and the human user should only see "Internal error" as the
+// Internal error and the human user should only see "Internal error" as the
// message. These low-level internal error details should only be logged and
// reported to the operator of the application (not the end user).
type Error struct {
// Machine-readable error code.
Code Code
- // Human-readable error message.
- Message string
+ // Embeded error.
+ Err error
}
// Error implements the error interface. Not used by the application otherwise.
func (e *Error) Error() string {
- return fmt.Sprintf("bytebase error: code=%d message=%s", e.Code, e.Message)
+ return fmt.Sprintf("bytebase error: code=%d message=%v", e.Code, e.Err)
}
// ErrorCode unwraps an application error and returns its code.
@@ -63,15 +63,15 @@ func ErrorMessage(err error) string {
if err == nil {
return ""
} else if errors.As(err, &e) {
- return e.Message
+ return e.Err.Error()
}
return "Internal error."
}
-// Errorf is a helper function to return an Error with a given code and formatted message.
-func Errorf(code Code, format string, args ...interface{}) *Error {
+// Errorf is a helper function to return an Error with a given code and error.
+func Errorf(code Code, err error) *Error {
return &Error{
- Code: code,
- Message: fmt.Sprintf(format, args...),
+ Code: code,
+ Err: err,
}
}
diff --git a/plugin/db/mysql/mysql.go b/plugin/db/mysql/mysql.go
index cddcee7056..d72b57838b 100644
--- a/plugin/db/mysql/mysql.go
+++ b/plugin/db/mysql/mysql.go
@@ -857,7 +857,7 @@ func formatError(err error) error {
}
func formatErrorWithQuery(err error, query string) error {
- return common.Errorf(common.DbExecutionError, fmt.Sprintf("failed to execute error: %v\n\nquery:\n%q", err, query))
+ return common.Errorf(common.DbExecutionError, fmt.Errorf("failed to execute error: %w\n\nquery:\n%q", err, query))
}
// Dump and restore
diff --git a/server/database.go b/server/database.go
index b10c540c36..8c2ab875fd 100644
--- a/server/database.go
+++ b/server/database.go
@@ -656,7 +656,7 @@ func GetDatabaseDriver(instance *api.Instance, databaseName string, logger *zap.
},
)
if err != nil {
- return nil, common.Errorf(common.DbConnectionFailure, fmt.Sprintf("failed to connect database %s/%s at %q:%q with user %q: %v", instance.Name, databaseName, instance.Host, instance.Port, instance.Username, err))
+ return nil, common.Errorf(common.DbConnectionFailure, fmt.Errorf("failed to connect database %s/%s at %q:%q with user %q: %w", instance.Name, databaseName, instance.Host, instance.Port, instance.Username, err))
}
return driver, nil
}
diff --git a/server/instance.go b/server/instance.go
index 2352b4ceef..fe3188412a 100644
--- a/server/instance.go
+++ b/server/instance.go
@@ -471,5 +471,5 @@ func (s *Server) FindInstanceAdminPasswordById(ctx context.Context, instanceId i
return dataSource.Password, nil
}
}
- return "", &common.Error{Code: common.NotFound, Message: fmt.Sprintf("missing admin password for instance: %d", instanceId)}
+ return "", &common.Error{Code: common.NotFound, Err: fmt.Errorf("missing admin password for instance: %d", instanceId)}
}
diff --git a/server/issue.go b/server/issue.go
index ad418eeded..02fbe9e132 100644
--- a/server/issue.go
+++ b/server/issue.go
@@ -499,7 +499,7 @@ func (s *Server) ChangeIssueStatus(ctx context.Context, issue *api.Issue, newSta
for _, stage := range issue.Pipeline.StageList {
for _, task := range stage.TaskList {
if task.Status != api.TaskDone {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("failed to resolve issue: %v, task %v has not finished", issue.Name, task.Name)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("failed to resolve issue: %v, task %v has not finished", issue.Name, task.Name)}
}
}
}
diff --git a/server/task.go b/server/task.go
index 670b703b1f..bfddd4fbc5 100644
--- a/server/task.go
+++ b/server/task.go
@@ -319,8 +319,8 @@ func (s *Server) ChangeTaskStatusWithPatch(ctx context.Context, task *api.Task,
if !allowTransition {
return nil, &common.Error{
- Code: common.Invalid,
- Message: fmt.Sprintf("Invalid task status transition from %v to %v. Applicable transition(s) %v", task.Status, taskStatusPatch.Status, applicableTaskStatusTransition[task.Status])}
+ Code: common.Invalid,
+ Err: fmt.Errorf("Invalid task status transition from %v to %v. Applicable transition(s) %v", task.Status, taskStatusPatch.Status, applicableTaskStatusTransition[task.Status])}
}
updatedTask, err := s.TaskService.PatchTaskStatus(ctx, taskStatusPatch)
diff --git a/server/task_check_executor_database_connect.go b/server/task_check_executor_database_connect.go
index c66002ac93..27f0436ca0 100644
--- a/server/task_check_executor_database_connect.go
+++ b/server/task_check_executor_database_connect.go
@@ -25,7 +25,7 @@ func (exec *TaskCheckDatabaseConnectExecutor) Run(ctx context.Context, server *S
}
task, err := server.TaskService.FindTask(ctx, taskFind)
if err != nil {
- return []api.TaskCheckResult{}, common.Errorf(common.Internal, err.Error())
+ return []api.TaskCheckResult{}, common.Errorf(common.Internal, err)
}
databaseFind := &api.DatabaseFind{
@@ -33,7 +33,7 @@ func (exec *TaskCheckDatabaseConnectExecutor) Run(ctx context.Context, server *S
}
database, err := server.ComposeDatabaseByFind(ctx, databaseFind)
if err != nil {
- return []api.TaskCheckResult{}, common.Errorf(common.Internal, err.Error())
+ return []api.TaskCheckResult{}, common.Errorf(common.Internal, err)
}
driver, err := GetDatabaseDriver(database.Instance, database.Name, exec.l)
diff --git a/server/task_check_executor_statement_advisor.go b/server/task_check_executor_statement_advisor.go
index 98ecadcf8d..c13d3ff905 100644
--- a/server/task_check_executor_statement_advisor.go
+++ b/server/task_check_executor_statement_advisor.go
@@ -24,7 +24,7 @@ type TaskCheckStatementAdvisorExecutor struct {
func (exec *TaskCheckStatementAdvisorExecutor) Run(ctx context.Context, server *Server, taskCheckRun *api.TaskCheckRun) (result []api.TaskCheckResult, err error) {
payload := &api.TaskCheckDatabaseStatementAdvisePayload{}
if err := json.Unmarshal([]byte(taskCheckRun.Payload), payload); err != nil {
- return []api.TaskCheckResult{}, common.Errorf(common.Invalid, fmt.Sprintf("invalid check statement advise payload: %v", err))
+ return []api.TaskCheckResult{}, common.Errorf(common.Invalid, fmt.Errorf("invalid check statement advise payload: %w", err))
}
var advisorType advisor.AdvisorType
@@ -46,7 +46,7 @@ func (exec *TaskCheckStatementAdvisorExecutor) Run(ctx context.Context, server *
payload.Statement,
)
if err != nil {
- return []api.TaskCheckResult{}, common.Errorf(common.Internal, fmt.Sprintf("failed to check statement: %v", err))
+ return []api.TaskCheckResult{}, common.Errorf(common.Internal, fmt.Errorf("failed to check statement: %w", err))
}
result = []api.TaskCheckResult{}
diff --git a/store/activity.go b/store/activity.go
index c360d9d510..730e5803d5 100644
--- a/store/activity.go
+++ b/store/activity.go
@@ -75,9 +75,9 @@ func (s *ActivityService) FindActivity(ctx context.Context, find *api.ActivityFi
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("activity not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("activity not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d activities with filter %+v, expect 1. ", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d activities with filter %+v, expect 1. ", len(list), find)}
}
return list[0], nil
}
@@ -282,7 +282,7 @@ func patchActivity(ctx context.Context, tx *Tx, patch *api.ActivityPatch) (*api.
return &activity, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("activity ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("activity ID not found: %d", patch.ID)}
}
// deleteActivity permanently deletes a activity by ID.
@@ -295,7 +295,7 @@ func deleteActivity(ctx context.Context, tx *Tx, delete *api.ActivityDelete) err
rows, _ := result.RowsAffected()
if rows == 0 {
- return &common.Error{Code: common.NotFound, Message: fmt.Sprintf("activity ID not found: %d", delete.ID)}
+ return &common.Error{Code: common.NotFound, Err: fmt.Errorf("activity ID not found: %d", delete.ID)}
}
return nil
diff --git a/store/backup.go b/store/backup.go
index 4670aa9b98..d46eece616 100644
--- a/store/backup.go
+++ b/store/backup.go
@@ -61,9 +61,9 @@ func (s *BackupService) FindBackup(ctx context.Context, find *api.BackupFind) (*
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("backup not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("backup not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d backups with filter %+v, expect 1. ", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d backups with filter %+v, expect 1. ", len(list), find)}
}
return list[0], nil
@@ -276,7 +276,7 @@ func (s *BackupService) patchBackup(ctx context.Context, tx *Tx, patch *api.Back
return &backup, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("backup ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("backup ID not found: %d", patch.ID)}
}
// FindBackupSetting finds the backup setting for a database.
@@ -293,9 +293,9 @@ func (s *BackupService) FindBackupSetting(ctx context.Context, find *api.BackupS
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("backup setting not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("backup setting not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d backup settings with filter %+v, expect 1. ", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d backup settings with filter %+v, expect 1. ", len(list), find)}
}
return list[0], nil
@@ -367,16 +367,16 @@ func (s *BackupService) UpsertBackupSetting(ctx context.Context, upsert *api.Bac
// Backup plan policy check for backup setting mutation.
if backupPlanPolicy.Schedule != api.BackupPlanPolicyScheduleUnset {
if !upsert.Enabled {
- return nil, &common.Error{Code: common.Invalid, Message: fmt.Sprintf("backup setting should not be disabled for backup plan policy schedule %q", backupPlanPolicy.Schedule)}
+ return nil, &common.Error{Code: common.Invalid, Err: fmt.Errorf("backup setting should not be disabled for backup plan policy schedule %q", backupPlanPolicy.Schedule)}
}
switch backupPlanPolicy.Schedule {
case api.BackupPlanPolicyScheduleDaily:
if upsert.DayOfWeek != -1 {
- return nil, &common.Error{Code: common.Invalid, Message: fmt.Sprintf("backup setting DayOfWeek should be unset for backup plan policy schedule %q", backupPlanPolicy.Schedule)}
+ return nil, &common.Error{Code: common.Invalid, Err: fmt.Errorf("backup setting DayOfWeek should be unset for backup plan policy schedule %q", backupPlanPolicy.Schedule)}
}
case api.BackupPlanPolicyScheduleWeekly:
if upsert.DayOfWeek == -1 {
- return nil, &common.Error{Code: common.Invalid, Message: fmt.Sprintf("backup setting DayOfWeek should be set for backup plan policy schedule %q", backupPlanPolicy.Schedule)}
+ return nil, &common.Error{Code: common.Invalid, Err: fmt.Errorf("backup setting DayOfWeek should be set for backup plan policy schedule %q", backupPlanPolicy.Schedule)}
}
}
}
diff --git a/store/bookmark.go b/store/bookmark.go
index 7c2a232e41..456ff2f08b 100644
--- a/store/bookmark.go
+++ b/store/bookmark.go
@@ -75,9 +75,9 @@ func (s *BookmarkService) FindBookmark(ctx context.Context, find *api.BookmarkFi
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("bookmark not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("bookmark not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d activities with filter %+v, expect 1. ", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d activities with filter %+v, expect 1. ", len(list), find)}
}
return list[0], nil
}
@@ -207,7 +207,7 @@ func deleteBookmark(ctx context.Context, tx *Tx, delete *api.BookmarkDelete) err
rows, _ := result.RowsAffected()
if rows == 0 {
- return &common.Error{Code: common.NotFound, Message: fmt.Sprintf("bookmark ID not found: %d", delete.ID)}
+ return &common.Error{Code: common.NotFound, Err: fmt.Errorf("bookmark ID not found: %d", delete.ID)}
}
return nil
diff --git a/store/column.go b/store/column.go
index 6277b2a61d..dfa8833c0d 100644
--- a/store/column.go
+++ b/store/column.go
@@ -76,9 +76,9 @@ func (s *ColumnService) FindColumn(ctx context.Context, find *api.ColumnFind) (*
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("column not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("column not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d columns with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d columns with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
@@ -313,5 +313,5 @@ func (s *ColumnService) patchColumn(ctx context.Context, tx *Tx, patch *api.Colu
return &column, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("column ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("column ID not found: %d", patch.ID)}
}
diff --git a/store/data_source.go b/store/data_source.go
index 9a986f06ce..d89cf8bd5e 100644
--- a/store/data_source.go
+++ b/store/data_source.go
@@ -80,9 +80,9 @@ func (s *DataSourceService) FindDataSource(ctx context.Context, find *api.DataSo
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("data source not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("data source not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d data sources with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d data sources with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
@@ -272,5 +272,5 @@ func (s *DataSourceService) patchDataSource(ctx context.Context, tx *Tx, patch *
return &dataSource, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("dataSource ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("dataSource ID not found: %d", patch.ID)}
}
diff --git a/store/database.go b/store/database.go
index ac03297cbc..96827301ea 100644
--- a/store/database.go
+++ b/store/database.go
@@ -143,9 +143,9 @@ func (s *DatabaseService) FindDatabase(ctx context.Context, find *api.DatabaseFi
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("database not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("database not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d databases with filter %+v, expect 1. ", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d databases with filter %+v, expect 1. ", len(list), find)}
}
if err := s.cache.UpsertCache(api.DatabaseCache, list[0].ID, list[0]); err != nil {
@@ -371,5 +371,5 @@ func (s *DatabaseService) patchDatabase(ctx context.Context, tx *Tx, patch *api.
return &database, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("database ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("database ID not found: %d", patch.ID)}
}
diff --git a/store/environment.go b/store/environment.go
index 8bc6ac30eb..5d3af56cae 100644
--- a/store/environment.go
+++ b/store/environment.go
@@ -100,9 +100,9 @@ func (s *EnvironmentService) FindEnvironment(ctx context.Context, find *api.Envi
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("environment not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("environment not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d environments with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d environments with filter %+v, expect 1", len(list), find)}
}
if err := s.cache.UpsertCache(api.EnvironmentCache, list[0].ID, list[0]); err != nil {
@@ -302,5 +302,5 @@ func (s *EnvironmentService) patchEnvironment(ctx context.Context, tx *Tx, patch
return &environment, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("environment ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("environment ID not found: %d", patch.ID)}
}
diff --git a/store/inbox.go b/store/inbox.go
index 7b957ba5ad..3ecee7ed66 100644
--- a/store/inbox.go
+++ b/store/inbox.go
@@ -77,9 +77,9 @@ func (s *InboxService) FindInbox(ctx context.Context, find *api.InboxFind) (*api
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("inbox not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("inbox not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d inboxes with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d inboxes with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
@@ -315,5 +315,5 @@ func (s *InboxService) patchInbox(ctx context.Context, tx *Tx, patch *api.InboxP
return &inbox, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("inbox ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("inbox ID not found: %d", patch.ID)}
}
diff --git a/store/instance.go b/store/instance.go
index 083a19e214..e8a6ff7e32 100644
--- a/store/instance.go
+++ b/store/instance.go
@@ -135,9 +135,9 @@ func (s *InstanceService) FindInstance(ctx context.Context, find *api.InstanceFi
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("instance not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("instance not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d instances with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d instances with filter %+v, expect 1", len(list), find)}
}
if err := s.cache.UpsertCache(api.InstanceCache, list[0].ID, list[0]); err != nil {
@@ -347,5 +347,5 @@ func patchInstance(ctx context.Context, tx *Tx, patch *api.InstancePatch) (*api.
return &instance, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("instance ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("instance ID not found: %d", patch.ID)}
}
diff --git a/store/instance_user.go b/store/instance_user.go
index 2405eac6c6..9fbc50143a 100644
--- a/store/instance_user.go
+++ b/store/instance_user.go
@@ -179,7 +179,7 @@ func deleteInstanceUser(ctx context.Context, tx *Tx, delete *api.InstanceUserDel
rows, _ := result.RowsAffected()
if rows == 0 {
- return &common.Error{Code: common.NotFound, Message: fmt.Sprintf("instance user ID not found: %d", delete.ID)}
+ return &common.Error{Code: common.NotFound, Err: fmt.Errorf("instance user ID not found: %d", delete.ID)}
}
return nil
diff --git a/store/issue.go b/store/issue.go
index 631324fc18..5810eb1248 100644
--- a/store/issue.go
+++ b/store/issue.go
@@ -90,9 +90,9 @@ func (s *IssueService) FindIssue(ctx context.Context, find *api.IssueFind) (*api
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("issue not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("issue not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d issues with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d issues with filter %+v, expect 1", len(list), find)}
}
if err := s.cache.UpsertCache(api.IssueCache, list[0].ID, list[0]); err != nil {
@@ -332,5 +332,5 @@ func (s *IssueService) patchIssue(ctx context.Context, tx *Tx, patch *api.IssueP
return &issue, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("unable to find issue ID to update: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("unable to find issue ID to update: %d", patch.ID)}
}
diff --git a/store/issue_subscriber.go b/store/issue_subscriber.go
index 1b0d4a8b4c..75db2bb8e8 100644
--- a/store/issue_subscriber.go
+++ b/store/issue_subscriber.go
@@ -167,7 +167,7 @@ func deleteIssueSubscriber(ctx context.Context, tx *Tx, delete *api.IssueSubscri
rows, _ := result.RowsAffected()
if rows == 0 {
- return &common.Error{Code: common.NotFound, Message: fmt.Sprintf("subscriber %d not found in issue %d", delete.SubscriberId, delete.IssueId)}
+ return &common.Error{Code: common.NotFound, Err: fmt.Errorf("subscriber %d not found in issue %d", delete.SubscriberId, delete.IssueId)}
}
return nil
diff --git a/store/member.go b/store/member.go
index e1a57397a5..0b3e894159 100644
--- a/store/member.go
+++ b/store/member.go
@@ -100,9 +100,9 @@ func (s *MemberService) FindMember(ctx context.Context, find *api.MemberFind) (*
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("member not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("member not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d members with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d members with filter %+v, expect 1", len(list), find)}
}
if err := s.cache.UpsertCache(api.MemberCache, list[0].PrincipalId, list[0]); err != nil {
@@ -288,5 +288,5 @@ func patchMember(ctx context.Context, tx *Tx, patch *api.MemberPatch) (*api.Memb
return &member, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("member ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("member ID not found: %d", patch.ID)}
}
diff --git a/store/pipeline.go b/store/pipeline.go
index 6dcd5428b5..451834bfcd 100644
--- a/store/pipeline.go
+++ b/store/pipeline.go
@@ -100,9 +100,9 @@ func (s *PipelineService) FindPipeline(ctx context.Context, find *api.PipelineFi
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("pipeline not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("pipeline not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d pipelines with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d pipelines with filter %+v, expect 1", len(list), find)}
}
if err := s.cache.UpsertCache(api.PipelineCache, list[0].ID, list[0]); err != nil {
@@ -269,5 +269,5 @@ func (s *PipelineService) patchPipeline(ctx context.Context, tx *Tx, patch *api.
return &pipeline, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("pipeline ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("pipeline ID not found: %d", patch.ID)}
}
diff --git a/store/policy.go b/store/policy.go
index b03c0d4fb2..e94b09234c 100644
--- a/store/policy.go
+++ b/store/policy.go
@@ -34,7 +34,7 @@ func (s *PolicyService) FindPolicy(ctx context.Context, find *api.PolicyFind) (*
// Validate policy type existence.
if find.Type != nil && *find.Type != "" {
if err := api.ValidatePolicy(*find.Type, ""); err != nil {
- return nil, &common.Error{Code: common.Invalid, Message: err.Error()}
+ return nil, &common.Error{Code: common.Invalid, Err: err}
}
}
tx, err := s.db.BeginTx(ctx, nil)
@@ -55,7 +55,7 @@ func (s *PolicyService) FindPolicy(ctx context.Context, find *api.PolicyFind) (*
Type: *find.Type,
}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d policy with filter %+v, expect 1. ", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d policy with filter %+v, expect 1. ", len(list), find)}
} else {
ret = list[0]
}
@@ -64,7 +64,7 @@ func (s *PolicyService) FindPolicy(ctx context.Context, find *api.PolicyFind) (*
// Return the default policy when there is no stored policy.
payload, err := api.GetDefaultPolicy(*find.Type)
if err != nil {
- return nil, &common.Error{Code: common.Internal, Message: err.Error()}
+ return nil, &common.Error{Code: common.Internal, Err: err}
}
ret.Payload = payload
}
@@ -134,7 +134,7 @@ func (s *PolicyService) UpsertPolicy(ctx context.Context, upsert *api.PolicyUpse
// Validate policy.
if upsert.Type != "" {
if err := api.ValidatePolicy(upsert.Type, upsert.Payload); err != nil {
- return nil, &common.Error{Code: common.Invalid, Message: err.Error()}
+ return nil, &common.Error{Code: common.Invalid, Err: err}
}
}
tx, err := s.db.BeginTx(ctx, nil)
diff --git a/store/principal.go b/store/principal.go
index 7e7e6df480..d7eef12db8 100644
--- a/store/principal.go
+++ b/store/principal.go
@@ -100,9 +100,9 @@ func (s *PrincipalService) FindPrincipal(ctx context.Context, find *api.Principa
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("principal not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("principal not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d principals with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d principals with filter %+v, expect 1", len(list), find)}
}
if err := s.cache.UpsertCache(api.PrincipalCache, list[0].ID, list[0]); err != nil {
@@ -286,5 +286,5 @@ func patchPrincipal(ctx context.Context, tx *Tx, patch *api.PrincipalPatch) (*ap
return &principal, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("principal ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("principal ID not found: %d", patch.ID)}
}
diff --git a/store/project.go b/store/project.go
index 43f17a630b..ead43239dd 100644
--- a/store/project.go
+++ b/store/project.go
@@ -101,9 +101,9 @@ func (s *ProjectService) FindProject(ctx context.Context, find *api.ProjectFind)
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("project not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("project not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d projects with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d projects with filter %+v, expect 1", len(list), find)}
}
if err := s.cache.UpsertCache(api.ProjectCache, list[0].ID, list[0]); err != nil {
@@ -315,5 +315,5 @@ func patchProject(ctx context.Context, tx *sql.Tx, patch *api.ProjectPatch) (*ap
return &project, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("project ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("project ID not found: %d", patch.ID)}
}
diff --git a/store/project_member.go b/store/project_member.go
index 9a6d4faeba..9e16b98a66 100644
--- a/store/project_member.go
+++ b/store/project_member.go
@@ -72,9 +72,9 @@ func (s *ProjectMemberService) FindProjectMember(ctx context.Context, find *api.
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("project member not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("project member not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d project members with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d project members with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
@@ -262,7 +262,7 @@ func patchProjectMember(ctx context.Context, tx *Tx, patch *api.ProjectMemberPat
return &projectMember, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("project member ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("project member ID not found: %d", patch.ID)}
}
// deleteProjectMember permanently deletes a projectMember by ID.
@@ -275,7 +275,7 @@ func deleteProjectMember(ctx context.Context, tx *Tx, delete *api.ProjectMemberD
rows, _ := result.RowsAffected()
if rows == 0 {
- return &common.Error{Code: common.NotFound, Message: fmt.Sprintf("project member ID not found: %d", delete.ID)}
+ return &common.Error{Code: common.NotFound, Err: fmt.Errorf("project member ID not found: %d", delete.ID)}
}
return nil
diff --git a/store/project_webhook.go b/store/project_webhook.go
index 534953a37d..0a8a343127 100644
--- a/store/project_webhook.go
+++ b/store/project_webhook.go
@@ -75,9 +75,9 @@ func (s *ProjectWebhookService) FindProjectWebhook(ctx context.Context, find *ap
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("project hook not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("project hook not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d project hooks with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d project hooks with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
@@ -298,7 +298,7 @@ func patchProjectWebhook(ctx context.Context, tx *Tx, patch *api.ProjectWebhookP
return &projectWebhook, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("project hook ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("project hook ID not found: %d", patch.ID)}
}
// deleteProjectWebhook permanently deletes a projectWebhook by ID.
@@ -311,7 +311,7 @@ func deleteProjectWebhook(ctx context.Context, tx *Tx, delete *api.ProjectWebhoo
rows, _ := result.RowsAffected()
if rows == 0 {
- return &common.Error{Code: common.NotFound, Message: fmt.Sprintf("project hook ID not found: %d", delete.ID)}
+ return &common.Error{Code: common.NotFound, Err: fmt.Errorf("project hook ID not found: %d", delete.ID)}
}
return nil
diff --git a/store/repository.go b/store/repository.go
index 767aa5218c..710145ca68 100644
--- a/store/repository.go
+++ b/store/repository.go
@@ -77,9 +77,9 @@ func (s *RepositoryService) FindRepository(ctx context.Context, find *api.Reposi
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("repository not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("repository not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d repositories with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d repositories with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
@@ -377,7 +377,7 @@ func patchRepository(ctx context.Context, tx *Tx, patch *api.RepositoryPatch) (*
return &repository, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("repository ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("repository ID not found: %d", patch.ID)}
}
// deleteRepository permanently deletes a repository by ID.
@@ -401,7 +401,7 @@ func (s *RepositoryService) deleteRepository(ctx context.Context, tx *Tx, delete
rows, _ := result.RowsAffected()
if rows == 0 {
- return &common.Error{Code: common.NotFound, Message: fmt.Sprintf("repository not found for project ID: %d", delete.ProjectId)}
+ return &common.Error{Code: common.NotFound, Err: fmt.Errorf("repository not found for project ID: %d", delete.ProjectId)}
}
return nil
diff --git a/store/setting.go b/store/setting.go
index daba72fbdd..63bad2db49 100644
--- a/store/setting.go
+++ b/store/setting.go
@@ -87,9 +87,9 @@ func (s *SettingService) FindSetting(ctx context.Context, find *api.SettingFind)
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("setting not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("setting not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d activities with filter %+v, expect 1. ", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d activities with filter %+v, expect 1. ", len(list), find)}
}
return list[0], nil
}
@@ -243,5 +243,5 @@ func patchSetting(ctx context.Context, tx *Tx, patch *api.SettingPatch) (*api.Se
return &setting, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("setting not found: %s", patch.Name)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("setting not found: %s", patch.Name)}
}
diff --git a/store/sqlite.go b/store/sqlite.go
index b10a221bfa..42205170ab 100644
--- a/store/sqlite.go
+++ b/store/sqlite.go
@@ -334,29 +334,29 @@ func FormatError(err error) error {
switch err.Error() {
case "UNIQUE constraint failed: principal.email":
- return common.Errorf(common.Conflict, "email already exists")
+ return common.Errorf(common.Conflict, fmt.Errorf("email already exists"))
case "UNIQUE constraint failed: member.principal_id":
- return common.Errorf(common.Conflict, "member already exists")
+ return common.Errorf(common.Conflict, fmt.Errorf("member already exists"))
case "UNIQUE constraint failed: environment.name":
- return common.Errorf(common.Conflict, "environment name already exists")
+ return common.Errorf(common.Conflict, fmt.Errorf("environment name already exists"))
case "UNIQUE constraint failed: project.key":
- return common.Errorf(common.Conflict, "project key already exists")
+ return common.Errorf(common.Conflict, fmt.Errorf("project key already exists"))
case "UNIQUE constraint failed: project_webhook.project_id, project_webhook.url":
- return common.Errorf(common.Conflict, "webhook url already exists")
+ return common.Errorf(common.Conflict, fmt.Errorf("webhook url already exists"))
case "UNIQUE constraint failed: project_member.project_id, project_member.principal_id":
- return common.Errorf(common.Conflict, "project member already exists")
+ return common.Errorf(common.Conflict, fmt.Errorf("project member already exists"))
case "UNIQUE constraint failed: db.instance_id, db.name":
- return common.Errorf(common.Conflict, "database name already exists")
+ return common.Errorf(common.Conflict, fmt.Errorf("database name already exists"))
case "UNIQUE constraint failed: data_source.instance_id, data_source.name":
- return common.Errorf(common.Conflict, "data source name already exists")
+ return common.Errorf(common.Conflict, fmt.Errorf("data source name already exists"))
case "UNIQUE constraint failed: backup.database_id, backup.name":
- return common.Errorf(common.Conflict, "backup name already exists")
+ return common.Errorf(common.Conflict, fmt.Errorf("backup name already exists"))
case "UNIQUE constraint failed: bookmark.creator_id, bookmark.link":
- return common.Errorf(common.Conflict, "bookmark already exists")
+ return common.Errorf(common.Conflict, fmt.Errorf("bookmark already exists"))
case "UNIQUE constraint failed: repository.project_id":
- return common.Errorf(common.Conflict, "project has already linked repository")
+ return common.Errorf(common.Conflict, fmt.Errorf("project has already linked repository"))
case "UNIQUE constraint failed: issue_subscriber.issue_id, issue_subscriber.subscriber_id":
- return common.Errorf(common.Conflict, "issue subscriber already exists")
+ return common.Errorf(common.Conflict, fmt.Errorf("issue subscriber already exists"))
default:
return err
}
diff --git a/store/stage.go b/store/stage.go
index fcc7cbb4f4..b56d271c3e 100644
--- a/store/stage.go
+++ b/store/stage.go
@@ -75,9 +75,9 @@ func (s *StageService) FindStage(ctx context.Context, find *api.StageFind) (*api
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("stage not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("stage not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d stages with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d stages with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
diff --git a/store/table.go b/store/table.go
index 6c18206a0c..4cd4724107 100644
--- a/store/table.go
+++ b/store/table.go
@@ -75,9 +75,9 @@ func (s *TableService) FindTable(ctx context.Context, find *api.TableFind) (*api
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("table not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("table not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d tables with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d tables with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
@@ -312,7 +312,7 @@ func (s *TableService) patchTable(ctx context.Context, tx *Tx, patch *api.TableP
return &table, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("table ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("table ID not found: %d", patch.ID)}
}
// deleteTable permanently deletes tables from a database.
diff --git a/store/table_index.go b/store/table_index.go
index 634b45bdad..8ae52470d8 100644
--- a/store/table_index.go
+++ b/store/table_index.go
@@ -75,9 +75,9 @@ func (s *IndexService) FindIndex(ctx context.Context, find *api.IndexFind) (*api
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("index not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("index not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d indexs with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d indexs with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
@@ -287,5 +287,5 @@ func (s *IndexService) patchIndex(ctx context.Context, tx *Tx, patch *api.IndexP
return &index, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("index ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("index ID not found: %d", patch.ID)}
}
diff --git a/store/task.go b/store/task.go
index 7cfe0c8ccd..81352af6af 100644
--- a/store/task.go
+++ b/store/task.go
@@ -223,9 +223,9 @@ func (s *TaskService) findTask(ctx context.Context, tx *Tx, find *api.TaskFind)
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("task not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("task not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d tasks with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d tasks with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
@@ -367,7 +367,7 @@ func (s *TaskService) patchTask(ctx context.Context, tx *Tx, patch *api.TaskPatc
return &task, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("task ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("task ID not found: %d", patch.ID)}
}
// patchTaskStatus updates a task status by ID. Returns the new state of the task after update.
@@ -496,5 +496,5 @@ func (s *TaskService) patchTaskStatus(ctx context.Context, tx *Tx, patch *api.Ta
return &task, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("task ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("task ID not found: %d", patch.ID)}
}
diff --git a/store/task_check_run.go b/store/task_check_run.go
index 071ac23ea1..080ff7fa75 100644
--- a/store/task_check_run.go
+++ b/store/task_check_run.go
@@ -173,9 +173,9 @@ func (s *TaskCheckRunService) FindTaskCheckRunTx(ctx context.Context, tx *sql.Tx
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("task run not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("task run not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d task runs with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d task runs with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
diff --git a/store/task_run.go b/store/task_run.go
index d494092400..ef5f2d4689 100644
--- a/store/task_run.go
+++ b/store/task_run.go
@@ -93,9 +93,9 @@ func (s *TaskRunService) FindTaskRunTx(ctx context.Context, tx *sql.Tx, find *ap
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("task run not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("task run not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d task runs with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d task runs with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
diff --git a/store/vcs.go b/store/vcs.go
index 76c33cdf29..e97df18083 100644
--- a/store/vcs.go
+++ b/store/vcs.go
@@ -75,9 +75,9 @@ func (s *VCSService) FindVCS(ctx context.Context, find *api.VCSFind) (*api.VCS,
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("vcs not found: %+v", find)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("vcs not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &common.Error{Code: common.Conflict, Message: fmt.Sprintf("found %d vcss with filter %+v, expect 1", len(list), find)}
+ return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d vcss with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
@@ -285,7 +285,7 @@ func patchVCS(ctx context.Context, tx *Tx, patch *api.VCSPatch) (*api.VCS, error
return &vcs, nil
}
- return nil, &common.Error{Code: common.NotFound, Message: fmt.Sprintf("vcs ID not found: %d", patch.ID)}
+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("vcs ID not found: %d", patch.ID)}
}
// deleteVCS permanently deletes a vcs by ID.
@@ -298,7 +298,7 @@ func deleteVCS(ctx context.Context, tx *Tx, delete *api.VCSDelete) error {
rows, _ := result.RowsAffected()
if rows == 0 {
- return &common.Error{Code: common.NotFound, Message: fmt.Sprintf("vcs ID not found: %d", delete.ID)}
+ return &common.Error{Code: common.NotFound, Err: fmt.Errorf("vcs ID not found: %d", delete.ID)}
}
return nil