Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor: store return nil on issue and pipeline related entity non-existence (#310)
spinningbotc94c3ea0e1c4
diff --git a/server/activity.go b/server/activity.goindex e8fac25ee2..95a2e61459 100644--- a/server/activity.go+++ b/server/activity.go@@ -30,11 +30,11 @@ func (s *Server) registerActivityRoutes(g *echo.Group) {}issue, err := s.IssueService.FindIssue(ctx, issueFind)if err != nil {- if common.ErrorCode(err) == common.NotFound {- return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to find issue ID for creating the comment: %d", activityCreate.ContainerID))- }return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch issue ID when creating the comment: %d", activityCreate.ContainerID)).SetInternal(err)}+ if issue == nil {+ return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Unable to find issue ID for creating the comment: %d", activityCreate.ContainerID))+ }bytes, err := json.Marshal(api.ActivityIssueCommentCreatePayload{IssueName: issue.Name,diff --git a/server/activity_manager.go b/server/activity_manager.goindex 9de2a4c46f..9a64d497af 100644--- a/server/activity_manager.go+++ b/server/activity_manager.go@@ -241,6 +241,14 @@ func (m *ActivityManager) getWebhookContext(ctx context.Context, activity *api.Azap.Error(err))return webhookCtx, err}+ if task == nil {+ err := fmt.Errorf("Failed to post webhook event after changing the issue task status, task not found for ID %v", update.TaskID)+ m.s.l.Warn(err.Error(),+ zap.String("issue_name", meta.issue.Name),+ zap.Int("task_id", update.TaskID),+ zap.Error(err))+ return webhookCtx, err+ }title = "Task changed - " + task.Nameswitch update.NewStatus {diff --git a/server/issue.go b/server/issue.goindex b0983a48c9..5628e5b875 100644--- a/server/issue.go+++ b/server/issue.go@@ -98,11 +98,11 @@ func (s *Server) registerIssueRoutes(g *echo.Group) {issue, err := s.composeIssueByID(ctx, id)if err != nil {- if common.ErrorCode(err) == common.NotFound {- return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Issue ID not found: %d", id))- }return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch issue ID: %v", id)).SetInternal(err)}+ if issue == nil {+ return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Issue ID not found: %d", id))+ }c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)if err := jsonapi.MarshalPayload(c.Response().Writer, issue); err != nil {@@ -131,11 +131,11 @@ func (s *Server) registerIssueRoutes(g *echo.Group) {}issue, err := s.IssueService.FindIssue(ctx, issueFind)if err != nil {- if common.ErrorCode(err) == common.NotFound {- return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Unable to find issue ID to update: %d", id))- }return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch issue ID when updating issue: %v", id)).SetInternal(err)}+ if issue == nil {+ return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Unable to find issue ID to update: %d", id))+ }updatedIssue, err := s.IssueService.PatchIssue(ctx, issuePatch)if err != nil {@@ -224,11 +224,11 @@ func (s *Server) registerIssueRoutes(g *echo.Group) {issue, err := s.composeIssueByID(ctx, id)if err != nil {- if common.ErrorCode(err) == common.NotFound {- return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Issue ID not found: %d", id))- }return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch issue ID: %v", id)).SetInternal(err)}+ if issue == nil {+ return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Issue ID not found: %d", id))+ }updatedIssue, err := s.changeIssueStatus(ctx, issue, issueStatusPatch.Status, issueStatusPatch.UpdaterID, issueStatusPatch.Comment)if err != nil {@@ -260,9 +260,14 @@ func (s *Server) composeIssueByID(ctx context.Context, id int) (*api.Issue, erroif err != nil {return nil, err}+ if id > 0 && issue == nil {+ return nil, fmt.Errorf("issue not found for ID %v", id)+ }- if err := s.composeIssueRelationship(ctx, issue); err != nil {- return nil, err+ if issue != nil {+ if err := s.composeIssueRelationship(ctx, issue); err != nil {+ return nil, err+ }}return issue, nil@@ -465,6 +470,9 @@ func (s *Server) createIssue(ctx context.Context, issueCreate *api.IssueCreate,if err != nil {return nil, fmt.Errorf("failed to create activity after creating the rollback issue: %v. Error %w", issue.Name, err)}+ if rollbackIssue == nil {+ return nil, fmt.Errorf("Rollback issue not found for ID %v", issueCreate.RollbackIssueID)+ }bytes, err := json.Marshal(api.ActivityIssueCommentCreatePayload{IssueName: rollbackIssue.Name,})diff --git a/server/pipeline.go b/server/pipeline.goindex 37fab0c6a7..9773e37a41 100644--- a/server/pipeline.go+++ b/server/pipeline.go@@ -15,10 +15,11 @@ func (s *Server) composePipelineByID(ctx context.Context, id int) (*api.Pipelinereturn nil, err}- if err := s.composePipelineRelationship(ctx, pipeline); err != nil {- return nil, err+ if pipeline != nil {+ if err := s.composePipelineRelationship(ctx, pipeline); err != nil {+ return nil, err+ }}-return pipeline, nil}diff --git a/server/sql.go b/server/sql.goindex 52d4b3de9b..010195d8f3 100644--- a/server/sql.go+++ b/server/sql.go@@ -304,26 +304,26 @@ func (s *Server) syncEngineVersionAndSchema(ctx context.Context, instance *api.IName: &index.Name,Expression: &index.Expression,}- _, err := s.IndexService.FindIndex(ctx, indexFind)+ index, err := s.IndexService.FindIndex(ctx, indexFind)if err != nil {- if common.ErrorCode(err) == common.NotFound {- indexCreate := &api.IndexCreate{- CreatorID: api.SystemBotID,- DatabaseID: database.ID,- TableID: upsertedTable.ID,- Name: index.Name,- Expression: index.Expression,- Position: index.Position,- Type: index.Type,- Unique: index.Unique,- Visible: index.Visible,- Comment: index.Comment,- }- if err := createIndex(database, upsertedTable, indexCreate); err != nil {- return err- }- } else {- return fmt.Errorf("failed to sync index for instance: %s, database: %s, table: %s. Error %w", instance.Name, database.Name, upsertedTable.Name, err)+ return fmt.Errorf("failed to sync index for instance: %s, database: %s, table: %s. Error %w", instance.Name, database.Name, upsertedTable.Name, err)+ }+ if index == nil {+ // Create index if not exists.+ indexCreate := &api.IndexCreate{+ CreatorID: api.SystemBotID,+ DatabaseID: database.ID,+ TableID: upsertedTable.ID,+ Name: index.Name,+ Expression: index.Expression,+ Position: index.Position,+ Type: index.Type,+ Unique: index.Unique,+ Visible: index.Visible,+ Comment: index.Comment,+ }+ if err := createIndex(database, upsertedTable, indexCreate); err != nil {+ return err}}}diff --git a/server/task.go b/server/task.goindex 84f755d321..4c8aabfbc4 100644--- a/server/task.go+++ b/server/task.go@@ -47,11 +47,11 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {}task, err := s.TaskService.FindTask(ctx, taskFind)if err != nil {- if common.ErrorCode(err) == common.NotFound {- return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Task ID not found: %d", taskID))- }return echo.NewHTTPError(http.StatusInternalServerError, "Failed to update task").SetInternal(err)}+ if task == nil {+ return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Task ID not found: %d", taskID))+ }if taskPatch.Statement != nil {if task.Status != api.TaskPending && task.Status != api.TaskPendingApproval && task.Status != api.TaskFailed {@@ -104,6 +104,10 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {if err != nil {return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch issue ID after updating task statement: %v", task.PipelineID)).SetInternal(err)}+ if issue == nil {+ err := fmt.Errorf("issue not found with pipeline ID %v", task.PipelineID)+ return echo.NewHTTPError(http.StatusNotFound, err).SetInternal(err)+ }payload, err := json.Marshal(api.ActivityPipelineTaskStatementUpdatePayload{TaskID: updatedTask.ID,@@ -185,6 +189,10 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {if err != nil {return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to fetch issue ID after updating task's earliest allowed time: %v", task.PipelineID)).SetInternal(err)}+ if issue == nil {+ err := fmt.Errorf("issue not found with pipeline ID %v", task.PipelineID)+ return echo.NewHTTPError(http.StatusNotFound, err.Error()).SetInternal(err)+ }payload, err := json.Marshal(api.ActivityPipelineTaskEarliestAllowedTimeUpdatePayload{TaskID: updatedTask.ID,@@ -261,11 +269,11 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {}task, err := s.TaskService.FindTask(ctx, taskFind)if err != nil {- if common.ErrorCode(err) == common.NotFound {- return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Task ID not found: %d", taskID))- }return echo.NewHTTPError(http.StatusInternalServerError, "Failed to update task status").SetInternal(err)}+ if task == nil {+ return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Task ID not found: %d", taskID))+ }updatedTask, err := s.changeTaskStatusWithPatch(ctx, task, taskStatusPatch)if err != nil {@@ -298,11 +306,11 @@ func (s *Server) registerTaskRoutes(g *echo.Group) {}task, err := s.TaskService.FindTask(ctx, taskFind)if err != nil {- if common.ErrorCode(err) == common.NotFound {- return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Task ID not found: %d", taskID))- }return echo.NewHTTPError(http.StatusInternalServerError, "Failed to update task status").SetInternal(err)}+ if task == nil {+ return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Task ID not found: %d", taskID))+ }skipIfAlreadyTerminated := falseupdatedTask, err := s.TaskCheckScheduler.ScheduleCheckIfNeeded(ctx, task, c.Get(getPrincipalIDContextKey()).(int), skipIfAlreadyTerminated)@@ -445,9 +453,7 @@ func (s *Server) changeTaskStatusWithPatch(ctx context.Context, task *api.Task,issue, err := s.IssueService.FindIssue(ctx, issueFind)if err != nil {// Not all pipelines belong to an issue, so it's OK if ENOTFOUND- if common.ErrorCode(err) != common.NotFound {- return nil, fmt.Errorf("failed to fetch containing issue after changing the task status: %v, err: %w", task.Name, err)- }+ return nil, fmt.Errorf("failed to fetch containing issue after changing the task status: %v, err: %w", task.Name, err)}// Create an activity@@ -589,6 +595,9 @@ func (s *Server) changeTaskStatusWithPatch(ctx context.Context, task *api.Task,if err != nil {return nil, fmt.Errorf("failed to fetch pipeline/issue as DONE after completing task %v", updatedTask.Name)}+ if pipeline == nil {+ return nil, fmt.Errorf("pipeline not found for ID %v", updatedTask.PipelineID)+ }lastStage := pipeline.StageList[len(pipeline.StageList)-1]if lastStage.TaskList[len(lastStage.TaskList)-1].ID == updatedTask.ID {if issue == nil {diff --git a/server/task_check_executor_database_connect.go b/server/task_check_executor_database_connect.goindex c7099b29cd..eb450c701b 100644--- a/server/task_check_executor_database_connect.go+++ b/server/task_check_executor_database_connect.go@@ -30,6 +30,16 @@ func (exec *TaskCheckDatabaseConnectExecutor) Run(ctx context.Context, server *Sif err != nil {return []api.TaskCheckResult{}, common.Errorf(common.Internal, err)}+ if task == nil {+ return []api.TaskCheckResult{+ {+ Status: api.TaskCheckStatusError,+ Code: common.Internal,+ Title: fmt.Sprintf("Failed to find task %v", taskCheckRun.TaskID),+ Content: err.Error(),+ },+ }, nil+ }databaseFind := &api.DatabaseFind{ID: task.DatabaseID,diff --git a/server/task_check_executor_migration_schema.go b/server/task_check_executor_migration_schema.goindex 1be88eec99..851ba3cd93 100644--- a/server/task_check_executor_migration_schema.go+++ b/server/task_check_executor_migration_schema.go@@ -30,6 +30,16 @@ func (exec *TaskCheckMigrationSchemaExecutor) Run(ctx context.Context, server *Sif err != nil {return []api.TaskCheckResult{}, common.Errorf(common.Internal, err)}+ if task == nil {+ return []api.TaskCheckResult{+ {+ Status: api.TaskCheckStatusError,+ Code: common.Internal,+ Title: "Error",+ Content: fmt.Sprintf("task not found for ID %v", taskCheckRun.TaskID),+ },+ }, nil+ }instance, err := server.composeInstanceByID(ctx, task.InstanceID)if err != nil {diff --git a/server/task_executor_database_create.go b/server/task_executor_database_create.goindex 4057a691d0..4834cf19f0 100644--- a/server/task_executor_database_create.go+++ b/server/task_executor_database_create.go@@ -104,6 +104,13 @@ func (exec *DatabaseCreateTaskExecutor) RunOnce(ctx context.Context, server *Serzap.Int("task_id", task.ID),zap.Error(err),)+ }+ if issue == nil {+ err := fmt.Errorf("Failed to fetch containing issue for composing the migration info, issue not found with pipeline ID %v", task.PipelineID)+ exec.l.Error(err.Error(),+ zap.Int("task_id", task.ID),+ zap.Error(err),+ )} else {mi.IssueID = strconv.Itoa(issue.ID)}diff --git a/server/task_executor_database_restore.go b/server/task_executor_database_restore.goindex c2f52396eb..3898419113 100644--- a/server/task_executor_database_restore.go+++ b/server/task_executor_database_restore.go@@ -163,10 +163,7 @@ func createBranchMigrationHistory(ctx context.Context, server *Server, sourceDat}issue, err := server.IssueService.FindIssue(ctx, issueFind)if err != nil {- // Not all pipelines belong to an issue, so it's OK if ENOTFOUND- if common.ErrorCode(err) != common.NotFound {- return -1, "", fmt.Errorf("failed to fetch containing issue when creating the migration history: %v, err: %w", task.Name, err)- }+ return -1, "", fmt.Errorf("failed to fetch containing issue when creating the migration history: %v, err: %w", task.Name, err)}// Add a branch migration history record.diff --git a/server/task_executor_schema_update.go b/server/task_executor_schema_update.goindex 5ad457e4f9..43d3c76d2c 100644--- a/server/task_executor_schema_update.go+++ b/server/task_executor_schema_update.go@@ -116,6 +116,14 @@ func (exec *SchemaUpdateTaskExecutor) RunOnce(ctx context.Context, server *Servezap.Int("task_id", task.ID),zap.Error(err),)+ }++ if issue == nil {+ err := fmt.Errorf("Failed to fetch containing issue for composing the migration info, issue not found with pipeline ID %v", task.PipelineID)+ exec.l.Error(err.Error(),+ zap.Int("task_id", task.ID),+ zap.Error(err),+ )} else {mi.IssueID = strconv.Itoa(issue.ID)}diff --git a/store/issue.go b/store/issue.goindex 1a2cac534d..799299d51f 100644--- a/store/issue.go+++ b/store/issue.go@@ -77,7 +77,6 @@ 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 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)@@ -89,16 +88,16 @@ func (s *IssueService) FindIssue(ctx context.Context, find *api.IssueFind) (*apilist, err := s.findIssueList(ctx, tx, find)if err != nil {return nil, err- } else if len(list) == 0 {- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("issue not found: %+v", find)}+ }++ if len(list) == 0 {+ return nil, nil} else if len(list) > 1 {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 {return nil, err}-return list[0], nil}diff --git a/store/pipeline.go b/store/pipeline.goindex 5e0ca0d8e8..0f6abf2da9 100644--- a/store/pipeline.go+++ b/store/pipeline.go@@ -76,7 +76,6 @@ 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 ECONFLICT if finding more than 1 matching records.func (s *PipelineService) FindPipeline(ctx context.Context, find *api.PipelineFind) (*api.Pipeline, error) {if find.ID != nil {@@ -99,16 +98,16 @@ func (s *PipelineService) FindPipeline(ctx context.Context, find *api.PipelineFilist, err := s.findPipelineList(ctx, tx, find)if err != nil {return nil, err- } else if len(list) == 0 {- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("pipeline not found: %+v", find)}+ }++ if len(list) == 0 {+ return nil, nil} else if len(list) > 1 {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 {return nil, err}-return list[0], nil}diff --git a/store/stage.go b/store/stage.goindex 60f7105864..f83bcff4eb 100644--- a/store/stage.go+++ b/store/stage.go@@ -62,7 +62,6 @@ 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 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)@@ -74,8 +73,10 @@ func (s *StageService) FindStage(ctx context.Context, find *api.StageFind) (*apilist, err := s.findStageList(ctx, tx, find)if err != nil {return nil, err- } else if len(list) == 0 {- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("stage not found: %+v", find)}+ }++ if len(list) == 0 {+ return nil, nil} else if len(list) > 1 {return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d stages with filter %+v, expect 1", len(list), find)}}diff --git a/store/table_index.go b/store/table_index.goindex 882017fb05..afd91c5dd8 100644--- a/store/table_index.go+++ b/store/table_index.go@@ -62,7 +62,6 @@ func (s *IndexService) FindIndexList(ctx context.Context, find *api.IndexFind) (}// FindIndex retrieves a single index based on find.-// Returns ENOTFOUND if no matching record.// Returns ECONFLICT if finding more than 1 matching records.func (s *IndexService) FindIndex(ctx context.Context, find *api.IndexFind) (*api.Index, error) {tx, err := s.db.BeginTx(ctx, nil)@@ -74,8 +73,10 @@ func (s *IndexService) FindIndex(ctx context.Context, find *api.IndexFind) (*apilist, err := s.findIndexList(ctx, tx, find)if err != nil {return nil, err- } else if len(list) == 0 {- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("index not found: %+v", find)}+ }++ if len(list) == 0 {+ return nil, nil} else if len(list) > 1 {return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d indexs with filter %+v, expect 1", len(list), find)}}diff --git a/store/task.go b/store/task.goindex b6cae3ee3d..a6c63cc9d5 100644--- a/store/task.go+++ b/store/task.go@@ -67,7 +67,6 @@ 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 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)@@ -393,6 +392,9 @@ func (s *TaskService) patchTaskStatus(ctx context.Context, tx *Tx, patch *api.Taif err != nil {return nil, err}+ if task == nil {+ return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("task ID not found: %d", patch.ID)}+ }if !(task.Status == api.TaskPendingApproval && patch.Status == api.TaskPending) {taskRunFind := &api.TaskRunFind{@@ -404,13 +406,14 @@ func (s *TaskService) patchTaskStatus(ctx context.Context, tx *Tx, patch *api.TataskRun, err := s.TaskRunService.FindTaskRunTx(ctx, tx.Tx, taskRunFind)if err != nil {if common.ErrorCode(err) == common.NotFound {- if patch.Status != api.TaskRunning {- return nil, fmt.Errorf("no applicable running task to change status")- }} else {return nil, err}- } else if patch.Status == api.TaskRunning {+ }+ if taskRun == nil && patch.Status != api.TaskRunning {+ return nil, fmt.Errorf("no applicable running task to change status")+ }+ if patch.Status == api.TaskRunning {return nil, fmt.Errorf("task is already running: %v", task.Name)}diff --git a/store/task_check_run.go b/store/task_check_run.goindex 4985d5da69..446be694b2 100644--- a/store/task_check_run.go+++ b/store/task_check_run.go@@ -166,14 +166,15 @@ func (s *TaskCheckRunService) FindTaskCheckRunListTx(ctx context.Context, tx *sq}// FindTaskCheckRunTx retrieves a single taskCheckRun based on find.-// Returns ENOTFOUND if no matching record.// Returns ECONFLICT if finding more than 1 matching records.func (s *TaskCheckRunService) FindTaskCheckRunTx(ctx context.Context, tx *sql.Tx, find *api.TaskCheckRunFind) (*api.TaskCheckRun, error) {list, err := s.findTaskCheckRunList(ctx, tx, find)if err != nil {return nil, err- } else if len(list) == 0 {- return nil, &common.Error{Code: common.NotFound, Err: fmt.Errorf("task run not found: %+v", find)}+ }++ if len(list) == 0 {+ return nil, nil} else if len(list) > 1 {return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d task runs with filter %+v, expect 1", len(list), find)}}diff --git a/store/task_run.go b/store/task_run.goindex a4b1e8e592..d38f430ce4 100644--- a/store/task_run.go+++ b/store/task_run.go@@ -88,14 +88,14 @@ func (s *TaskRunService) FindTaskRunListTx(ctx context.Context, tx *sql.Tx, find}// FindTaskRunTx retrieves a single taskRun based on find.-// Returns ENOTFOUND if no matching record.// Returns ECONFLICT if finding more than 1 matching records.func (s *TaskRunService) FindTaskRunTx(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, &common.Error{Code: common.NotFound, Err: fmt.Errorf("task run not found: %+v", find)}+ }+ if len(list) == 0 {+ return nil, nil} else if len(list) > 1 {return nil, &common.Error{Code: common.Conflict, Err: fmt.Errorf("found %d task runs with filter %+v, expect 1", len(list), find)}}