diff --git a/engine/api/workflow/dao_run.go b/engine/api/workflow/dao_run.go index fcbb4f37c3..354060594f 100644 --- a/engine/api/workflow/dao_run.go +++ b/engine/api/workflow/dao_run.go @@ -19,6 +19,7 @@ import ( "github.com/ovh/cds/engine/api/authentication" "github.com/ovh/cds/engine/api/database/gorpmapping" "github.com/ovh/cds/engine/api/services" + "github.com/ovh/cds/engine/gorpmapper" "github.com/ovh/cds/sdk" "github.com/ovh/cds/sdk/telemetry" ) @@ -84,7 +85,12 @@ func UpdateWorkflowRun(ctx context.Context, db gorp.SqlExecutor, wr *sdk.Workflo runDB := Run(*wr) if _, err := db.Update(&runDB); err != nil { - return sdk.WrapError(err, "Unable to update workflow run") + if e, ok := err.(*pq.Error); ok { + if e.Code == gorpmapper.ViolateUniqueKeyPGCode { + return sdk.NewError(sdk.ErrConflictData, e) + } + } + return sdk.WrapError(err, "unable to update workflow run") } wr.ID = runDB.ID return nil @@ -284,7 +290,7 @@ func LoadRunsIDsToDelete(db gorp.SqlExecutor, offset int64, limit int64) ([]int6 } var ids []int64 - querySelect := `SELECT id FROM workflow_run + querySelect := `SELECT id FROM workflow_run WHERE to_delete = true ORDER BY workflow_run.start ASC limit $1 offset $2` _, err = db.Select(&ids, querySelect, limit, offset) diff --git a/engine/api/workflow_queue.go b/engine/api/workflow_queue.go index 6ec28e054c..3d41df0bee 100644 --- a/engine/api/workflow_queue.go +++ b/engine/api/workflow_queue.go @@ -1228,11 +1228,14 @@ func (api *API) postWorkflowJobSetVersionHandler() service.Handler { } if workflowRun.Version != nil && *workflowRun.Version != data.Value { - return sdk.NewErrorFrom(sdk.ErrForbidden, "cannot change existing workflow run version value") + return sdk.NewErrorFrom(sdk.ErrForbidden, "cannot change existing workflow run version value %q", *workflowRun.Version) } workflowRun.Version = &data.Value if err := workflow.UpdateWorkflowRun(ctx, tx, workflowRun); err != nil { + if sdk.ErrorIs(err, sdk.ErrConflictData) { + return sdk.NewErrorFrom(err, "version %q already used by another workflow run", data.Value) + } return err } diff --git a/sdk/workflow_run.go b/sdk/workflow_run.go index a0c45588b5..3e45bfb57a 100644 --- a/sdk/workflow_run.go +++ b/sdk/workflow_run.go @@ -192,7 +192,7 @@ type WorkflowRunVersion struct { func (w WorkflowRunVersion) IsValid() error { _, err := semver.ParseTolerant(w.Value) if err != nil { - return NewError(ErrWrongRequest, fmt.Errorf("value '%s' is not semver compatible: %v", w.Value, err)) + return NewError(ErrWrongRequest, fmt.Errorf("value %q is not semver compatible: %v", w.Value, err)) } return nil }