Skip to content

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

Return ECONFLICT instead of just emitting warning if we expect to get at most one row, but actually get mutitple rows

天舟f8128c1e7be9
diff --git a/store/activity.go b/store/activity.go
index 6cd463b34f..3e22e1383c 100644
--- a/store/activity.go
+++ b/store/activity.go
@@ -63,7 +63,7 @@ func (s *ActivityService) FindActivityList(ctx context.Context, find *api.Activi
// FindActivity retrieves a single activity based on find.
// Returns ENOTFOUND if no matching record.
-// Returns the first matching one and prints a warning if finding more than 1 matching records.
+// Returns ECONFLICT if finding more than 1 matching records.
func (s *ActivityService) FindActivity(ctx context.Context, find *api.ActivityFind) (*api.Activity, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
@@ -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, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("activity not found: %v", find)}
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("activity not found: %+v", find)}
} else if len(list) > 1 {
- s.l.Warn(fmt.Sprintf("found %d activities with filter %v, expect 1. ", len(list), find))
+ return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d activities with filter %+v, expect 1. ", len(list), find)}
}
return list[0], nil
}
diff --git a/store/bookmark.go b/store/bookmark.go
index 969b889526..c5a0024bbd 100644
--- a/store/bookmark.go
+++ b/store/bookmark.go
@@ -63,7 +63,7 @@ func (s *BookmarkService) FindBookmarkList(ctx context.Context, find *api.Bookma
// FindBookmark retrieves a single bookmark based on find.
// Returns ENOTFOUND if no matching record.
-// Returns the first matching one and prints a warning if finding more than 1 matching records.
+// Returns ECONFLICT if finding more than 1 matching records.
func (s *BookmarkService) FindBookmark(ctx context.Context, find *api.BookmarkFind) (*api.Bookmark, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
@@ -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, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("bookmark not found: %v", find)}
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("bookmark not found: %+v", find)}
} else if len(list) > 1 {
- s.l.Warn(fmt.Sprintf("found %d activities with filter %v, expect 1. ", len(list), find))
+ return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d activities with filter %+v, expect 1. ", len(list), find)}
}
return list[0], nil
}
diff --git a/store/config.go b/store/config.go
index cd8a399ae0..3424b14784 100644
--- a/store/config.go
+++ b/store/config.go
@@ -72,9 +72,9 @@ func (s *ConfigService) FindConfig(ctx context.Context, find *api.ConfigFind) (*
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("config not found: %v", find)}
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("config not found: %+v", find)}
} else if len(list) > 1 {
- return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d activities with filter %v, expect 1. ", len(list), find)}
+ return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d activities with filter %+v, expect 1. ", len(list), find)}
}
return list[0], nil
}
diff --git a/store/dataSource.go b/store/dataSource.go
index fdb8f909c4..6a3da61d29 100644
--- a/store/dataSource.go
+++ b/store/dataSource.go
@@ -68,7 +68,7 @@ func (s *DataSourceService) FindDataSourceList(ctx context.Context, find *api.Da
// FindDataSource retrieves a single dataSource based on find.
// Returns ENOTFOUND if no matching record.
-// Returns the first matching one and prints a warning if finding more than 1 matching records.
+// Returns ECONFLICT if finding more than 1 matching records.
func (s *DataSourceService) FindDataSource(ctx context.Context, find *api.DataSourceFind) (*api.DataSource, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
@@ -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, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("data source not found: %v", find)}
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("data source not found: %+v", find)}
} else if len(list) > 1 {
- s.l.Warn(fmt.Sprintf("found mulitple data sources: %d, expect 1", len(list)))
+ return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d data sources with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
diff --git a/store/database.go b/store/database.go
index cb004f7f3e..a89606fd3f 100644
--- a/store/database.go
+++ b/store/database.go
@@ -68,7 +68,7 @@ func (s *DatabaseService) FindDatabaseList(ctx context.Context, find *api.Databa
// FindDatabase retrieves a single database based on find.
// Returns ENOTFOUND if no matching record.
-// Returns the first matching one and prints a warning if finding more than 1 matching records.
+// Returns ECONFLICT if finding more than 1 matching records.
func (s *DatabaseService) FindDatabase(ctx context.Context, find *api.DatabaseFind) (*api.Database, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
@@ -80,9 +80,9 @@ func (s *DatabaseService) FindDatabase(ctx context.Context, find *api.DatabaseFi
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("database not found: %v", find)}
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("database not found: %+v", find)}
} else if len(list) > 1 {
- s.l.Warn(fmt.Sprintf("found %d databases with filter %v, expect 1. ", len(list), find))
+ return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d databases with filter %+v, expect 1. ", len(list), find)}
}
return list[0], nil
}
diff --git a/store/environment.go b/store/environment.go
index 2c338dd418..ca9bc88e53 100644
--- a/store/environment.go
+++ b/store/environment.go
@@ -63,7 +63,7 @@ func (s *EnvironmentService) FindEnvironmentList(ctx context.Context, find *api.
// FindEnvironment retrieves a single environment based on find.
// Returns ENOTFOUND if no matching record.
-// Returns the first matching one and prints a warning if finding more than 1 matching records.
+// Returns ECONFLICT if finding more than 1 matching records.
func (s *EnvironmentService) FindEnvironment(ctx context.Context, find *api.EnvironmentFind) (*api.Environment, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
@@ -75,9 +75,9 @@ func (s *EnvironmentService) FindEnvironment(ctx context.Context, find *api.Envi
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("environment not found: %v", find)}
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("environment not found: %+v", find)}
} else if len(list) > 1 {
- s.l.Warn(fmt.Sprintf("found mulitple environments: %d, expect 1", len(list)))
+ return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d environments with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
diff --git a/store/instance.go b/store/instance.go
index 4484f46bc1..fd0b7421bd 100644
--- a/store/instance.go
+++ b/store/instance.go
@@ -95,7 +95,7 @@ func (s *InstanceService) FindInstanceList(ctx context.Context, find *api.Instan
// FindInstance retrieves a single instance based on find.
// Returns ENOTFOUND if no matching record.
-// Returns the first matching one and prints a warning if finding more than 1 matching records.
+// Returns ECONFLICT if finding more than 1 matching records.
func (s *InstanceService) FindInstance(ctx context.Context, find *api.InstanceFind) (*api.Instance, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
@@ -107,9 +107,9 @@ func (s *InstanceService) FindInstance(ctx context.Context, find *api.InstanceFi
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("instance not found: %v", find)}
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("instance not found: %+v", find)}
} else if len(list) > 1 {
- s.l.Warn(fmt.Sprintf("found mulitple instances: %d, expect 1", len(list)))
+ return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d instances with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
diff --git a/store/issue.go b/store/issue.go
index f97c3839cc..371faa38a3 100644
--- a/store/issue.go
+++ b/store/issue.go
@@ -65,7 +65,7 @@ func (s *IssueService) FindIssueList(ctx context.Context, find *api.IssueFind) (
// FindIssue retrieves a single issue based on find.
// Returns ENOTFOUND if no matching record.
-// Returns the first matching one and prints a warning if finding more than 1 matching records.
+// Returns ECONFLICT if finding more than 1 matching records.
func (s *IssueService) FindIssue(ctx context.Context, find *api.IssueFind) (*api.Issue, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
@@ -77,9 +77,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, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("issue not found: %v", find)}
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("issue not found: %+v", find)}
} else if len(list) > 1 {
- s.l.Warn(fmt.Sprintf("found mulitple issues: %d, expect 1", len(list)))
+ return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d issues with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
diff --git a/store/member.go b/store/member.go
index feb5e941bb..f2d049c2cf 100644
--- a/store/member.go
+++ b/store/member.go
@@ -63,7 +63,7 @@ func (s *MemberService) FindMemberList(ctx context.Context, find *api.MemberFind
// FindMember retrieves a single member based on find.
// Returns ENOTFOUND if no matching record.
-// Returns the first matching one and prints a warning if finding more than 1 matching records.
+// Returns ECONFLICT if finding more than 1 matching records.
func (s *MemberService) FindMember(ctx context.Context, find *api.MemberFind) (*api.Member, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
@@ -75,9 +75,9 @@ func (s *MemberService) FindMember(ctx context.Context, find *api.MemberFind) (*
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("member not found: %v", find)}
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("member not found: %+v", find)}
} else if len(list) > 1 {
- s.l.Warn(fmt.Sprintf("found mulitple members: %d, expect 1", len(list)))
+ return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d members with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
diff --git a/store/pipeline.go b/store/pipeline.go
index e28b6cccb5..371d74f2d3 100644
--- a/store/pipeline.go
+++ b/store/pipeline.go
@@ -63,7 +63,7 @@ func (s *PipelineService) FindPipelineList(ctx context.Context, find *api.Pipeli
// FindPipeline retrieves a single pipeline based on find.
// Returns ENOTFOUND if no matching record.
-// Returns the first matching one and prints a warning if finding more than 1 matching records.
+// Returns ECONFLICT if finding more than 1 matching records.
func (s *PipelineService) FindPipeline(ctx context.Context, find *api.PipelineFind) (*api.Pipeline, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
@@ -75,9 +75,9 @@ func (s *PipelineService) FindPipeline(ctx context.Context, find *api.PipelineFi
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("pipeline not found: %v", find)}
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("pipeline not found: %+v", find)}
} else if len(list) > 1 {
- s.l.Warn(fmt.Sprintf("found mulitple pipelines: %d, expect 1", len(list)))
+ return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d pipelines with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
diff --git a/store/principal.go b/store/principal.go
index 5c7688bef2..864ea02c0d 100644
--- a/store/principal.go
+++ b/store/principal.go
@@ -63,7 +63,7 @@ func (s *PrincipalService) FindPrincipalList(ctx context.Context, find *api.Prin
// FindPrincipal retrieves a principal based on find.
// Returns ENOTFOUND if no matching record.
-// Returns the first matching one and prints a warning if finding more than 1 matching records.
+// Returns ECONFLICT if finding more than 1 matching records.
func (s *PrincipalService) FindPrincipal(ctx context.Context, find *api.PrincipalFind) (*api.Principal, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
@@ -75,9 +75,9 @@ func (s *PrincipalService) FindPrincipal(ctx context.Context, find *api.Principa
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("principal not found: %v", find)}
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("principal not found: %+v", find)}
} else if len(list) > 1 {
- s.l.Warn(fmt.Sprintf("found mulitple principals: %d, expect 1", len(list)))
+ return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d principals with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
diff --git a/store/project.go b/store/project.go
index c6d9da4713..0f52dbaac2 100644
--- a/store/project.go
+++ b/store/project.go
@@ -64,7 +64,7 @@ func (s *ProjectService) FindProjectList(ctx context.Context, find *api.ProjectF
// FindProject retrieves a single project based on find.
// Returns ENOTFOUND if no matching record.
-// Returns the first matching one and prints a warning if finding more than 1 matching records.
+// Returns ECONFLICT if finding more than 1 matching records.
func (s *ProjectService) FindProject(ctx context.Context, find *api.ProjectFind) (*api.Project, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
@@ -76,9 +76,9 @@ func (s *ProjectService) FindProject(ctx context.Context, find *api.ProjectFind)
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("project not found: %v", find)}
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("project not found: %+v", find)}
} else if len(list) > 1 {
- s.l.Warn(fmt.Sprintf("found mulitple projects: %d, expect 1", len(list)))
+ return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d projects with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
diff --git a/store/project_member.go b/store/project_member.go
index 8981714507..5f9d0c905a 100644
--- a/store/project_member.go
+++ b/store/project_member.go
@@ -63,7 +63,7 @@ func (s *ProjectMemberService) FindProjectMemberList(ctx context.Context, find *
// FindProjectMember retrieves a single projectMember based on find.
// Returns ENOTFOUND if no matching record.
-// Returns the first matching one and prints a warning if finding more than 1 matching records.
+// Returns ECONFLICT if finding more than 1 matching records.
func (s *ProjectMemberService) FindProjectMember(ctx context.Context, find *api.ProjectMemberFind) (*api.ProjectMember, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
@@ -75,9 +75,9 @@ func (s *ProjectMemberService) FindProjectMember(ctx context.Context, find *api.
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("project member not found: %v", find)}
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("project member not found: %+v", find)}
} else if len(list) > 1 {
- s.l.Warn(fmt.Sprintf("found mulitple project members: %d, expect 1", len(list)))
+ return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d project members with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
diff --git a/store/repository.go b/store/repository.go
index de8a305d8d..5a73895ace 100644
--- a/store/repository.go
+++ b/store/repository.go
@@ -65,7 +65,7 @@ func (s *RepositoryService) FindRepositoryList(ctx context.Context, find *api.Re
// FindRepository retrieves a single repository based on find.
// Returns ENOTFOUND if no matching record.
-// Returns the first matching one and prints a warning if finding more than 1 matching records.
+// Returns ECONFLICT if finding more than 1 matching records.
func (s *RepositoryService) FindRepository(ctx context.Context, find *api.RepositoryFind) (*api.Repository, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
@@ -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, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("repository not found: %v", find)}
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("repository not found: %+v", find)}
} else if len(list) > 1 {
- s.l.Warn(fmt.Sprintf("found mulitple repositories: %d, expect 1", len(list)))
+ return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d repositories with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
diff --git a/store/stage.go b/store/stage.go
index 0e9b0c8290..f4ab351f52 100644
--- a/store/stage.go
+++ b/store/stage.go
@@ -63,7 +63,7 @@ func (s *StageService) FindStageList(ctx context.Context, find *api.StageFind) (
// FindStage retrieves a single stage based on find.
// Returns ENOTFOUND if no matching record.
-// Returns the first matching one and prints a warning if finding more than 1 matching records.
+// Returns ECONFLICT if finding more than 1 matching records.
func (s *StageService) FindStage(ctx context.Context, find *api.StageFind) (*api.Stage, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
@@ -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, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("stage not found: %v", find)}
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("stage not found: %+v", find)}
} else if len(list) > 1 {
- s.l.Warn(fmt.Sprintf("found mulitple stages: %d, expect 1", len(list)))
+ return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("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 aeb2a5d441..bb1807a526 100644
--- a/store/table.go
+++ b/store/table.go
@@ -63,7 +63,7 @@ func (s *TableService) FindTableList(ctx context.Context, find *api.TableFind) (
// FindTable retrieves a single table based on find.
// Returns ENOTFOUND if no matching record.
-// Returns the first matching one and prints a warning if finding more than 1 matching records.
+// Returns ECONFLICT if finding more than 1 matching records.
func (s *TableService) FindTable(ctx context.Context, find *api.TableFind) (*api.Table, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
@@ -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, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("table not found: %v", find)}
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("table not found: %+v", find)}
} else if len(list) > 1 {
- s.l.Warn(fmt.Sprintf("found %d tables with filter %v, expect 1. ", len(list), find))
+ return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d tables with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}
diff --git a/store/task.go b/store/task.go
index 775e7e865b..4cf898f901 100644
--- a/store/task.go
+++ b/store/task.go
@@ -67,7 +67,7 @@ func (s *TaskService) FindTaskList(ctx context.Context, find *api.TaskFind) ([]*
// FindTask retrieves a single task based on find.
// Returns ENOTFOUND if no matching record.
-// Returns the first matching one and prints a warning if finding more than 1 matching records.
+// Returns ECONFLICT if finding more than 1 matching records.
func (s *TaskService) FindTask(ctx context.Context, find *api.TaskFind) (*api.Task, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
@@ -200,9 +200,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, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("task not found: %v", find)}
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("task not found: %+v", find)}
} else if len(list) > 1 {
- s.l.Warn(fmt.Sprintf("found mulitple tasks: %d, expect 1", len(list)))
+ return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d tasks 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 dcacd70783..90a7fd34bf 100644
--- a/store/task_run.go
+++ b/store/task_run.go
@@ -87,15 +87,15 @@ func (s *TaskRunService) FindTaskRunList(ctx context.Context, tx *sql.Tx, find *
// FindTaskRun retrieves a single taskRun based on find.
// Returns ENOTFOUND if no matching record.
-// Returns the first matching one and prints a warning if finding more than 1 matching records.
+// Returns ECONFLICT if finding more than 1 matching records.
func (s *TaskRunService) FindTaskRun(ctx context.Context, tx *sql.Tx, find *api.TaskRunFind) (*api.TaskRun, error) {
list, err := s.findTaskRunList(ctx, tx, find)
if err != nil {
return nil, err
} else if len(list) == 0 {
- return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("task run not found: %v", find)}
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("task run not found: %+v", find)}
} else if len(list) > 1 {
- s.l.Warn(fmt.Sprintf("found mulitple task runs: %d, expect 1\n", len(list)))
+ return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("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 4733735330..249f3f2398 100644
--- a/store/vcs.go
+++ b/store/vcs.go
@@ -63,7 +63,7 @@ func (s *VCSService) FindVCSList(ctx context.Context, find *api.VCSFind) ([]*api
// FindVCS retrieves a single vcs based on find.
// Returns ENOTFOUND if no matching record.
-// Returns the first matching one and prints a warning if finding more than 1 matching records.
+// Returns ECONFLICT if finding more than 1 matching records.
func (s *VCSService) FindVCS(ctx context.Context, find *api.VCSFind) (*api.VCS, error) {
tx, err := s.db.BeginTx(ctx, nil)
if err != nil {
@@ -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, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("vcs not found: %v", find)}
+ return nil, &bytebase.Error{Code: bytebase.ENOTFOUND, Message: fmt.Sprintf("vcs not found: %+v", find)}
} else if len(list) > 1 {
- s.l.Warn(fmt.Sprintf("found mulitple vcss: %d, expect 1", len(list)))
+ return nil, &bytebase.Error{Code: bytebase.ECONFLICT, Message: fmt.Sprintf("found %d vcss with filter %+v, expect 1", len(list), find)}
}
return list[0], nil
}