From 25a13f2cbfb79a55267b06fe8b205337c7835b0d Mon Sep 17 00:00:00 2001 From: Guiheux Steven Date: Mon, 1 Mar 2021 14:45:09 +0100 Subject: [PATCH] fix: change error to have more details (#5724) --- engine/worker/cmd_tag.go | 3 +-- engine/worker/internal/action/builtin_script.go | 6 +++--- engine/worker/internal/handler_tag.go | 7 ++++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/engine/worker/cmd_tag.go b/engine/worker/cmd_tag.go index 1756accab7..cf75bd87ad 100644 --- a/engine/worker/cmd_tag.go +++ b/engine/worker/cmd_tag.go @@ -78,9 +78,8 @@ func tagCmd() func(cmd *cobra.Command, args []string) { resp, errDo := client.Do(req) if errDo != nil { - sdk.Exit("command failed: %v\n", errDo) + sdk.Exit("http call failed: %v\n", errDo) } - if resp.StatusCode >= 300 { body, err := ioutil.ReadAll(resp.Body) if err != nil { diff --git a/engine/worker/internal/action/builtin_script.go b/engine/worker/internal/action/builtin_script.go index 8b5297f82b..c6e5cc6b02 100644 --- a/engine/worker/internal/action/builtin_script.go +++ b/engine/worker/internal/action/builtin_script.go @@ -228,7 +228,7 @@ func RunScriptAction(ctx context.Context, wk workerruntime.Runtime, a sdk.Action stdout, err := cmd.StdoutPipe() if err != nil { - chanErr <- fmt.Errorf("Failure due to internal error: unable to capture stdout: %v", err) + chanErr <- fmt.Errorf("failure due to internal error: unable to capture stdout: %v", err) res.Status = sdk.StatusFail chanRes <- res return @@ -236,7 +236,7 @@ func RunScriptAction(ctx context.Context, wk workerruntime.Runtime, a sdk.Action stderr, err := cmd.StderrPipe() if err != nil { - chanErr <- fmt.Errorf("Failure due to internal error: unable to capture stderr: %v", err) + chanErr <- fmt.Errorf("failure due to internal error: unable to capture stderr: %v", err) res.Status = sdk.StatusFail chanRes <- res return @@ -303,7 +303,7 @@ func RunScriptAction(ctx context.Context, wk workerruntime.Runtime, a sdk.Action case globalErr = <-chanErr: } - log.Info(ctx, "runScriptAction> %s %s", res.Status, res.Reason) + log.Info(ctx, "runScriptAction> %s %s %v", res.Status, res.Reason, globalErr) return res, globalErr } diff --git a/engine/worker/internal/handler_tag.go b/engine/worker/internal/handler_tag.go index a0e1fabf9e..92b85feb61 100644 --- a/engine/worker/internal/handler_tag.go +++ b/engine/worker/internal/handler_tag.go @@ -16,7 +16,7 @@ func tagHandler(ctx context.Context, wk *CurrentWorker) http.HandlerFunc { ctx = workerruntime.SetStepName(ctx, wk.currentJob.currentStepName) if err := r.ParseForm(); err != nil { - writeError(w, r, err) + writeError(w, r, sdk.NewErrorFrom(sdk.ErrInvalidData, "unable to parse form %v", err)) return } tags := []sdk.WorkflowRunTag{} @@ -27,10 +27,11 @@ func tagHandler(ctx context.Context, wk *CurrentWorker) http.HandlerFunc { }) } - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + ctx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() if err := wk.client.QueueJobTag(ctx, wk.currentJob.wJob.ID, tags); err != nil { - writeError(w, r, err) + newError := sdk.NewErrorFrom(sdk.ErrUnknownError, "unable to create tag on CDS: %v", err) + writeError(w, r, newError) return } }