Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): return more info for error on worker set-version #5813

Merged
merged 1 commit into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions engine/api/workflow/dao_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion engine/api/workflow_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/workflow_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down