Skip to content

Commit

Permalink
fix: change error to have more details (#5724)
Browse files Browse the repository at this point in the history
  • Loading branch information
sguiheux authored Mar 1, 2021
1 parent 90cc51b commit 25a13f2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
3 changes: 1 addition & 2 deletions engine/worker/cmd_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions engine/worker/internal/action/builtin_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,15 @@ 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
}

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
Expand Down Expand Up @@ -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
}

Expand Down
7 changes: 4 additions & 3 deletions engine/worker/internal/handler_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand All @@ -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
}
}
Expand Down

0 comments on commit 25a13f2

Please sign in to comment.