Skip to content

Commit

Permalink
fix: return simple error message when step execution fails (#168)
Browse files Browse the repository at this point in the history
* fix: return simple error message when step execution fails

* ci: fix example step workflow
  • Loading branch information
aweris authored Oct 31, 2023
1 parent bb6a91d commit c9b01b3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ci/workflows/step.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ jobs:
with:
args: log --pretty=oneline

- name: Print go.mod
- name: Print go.work
uses: docker://alpine:latest
with:
entrypoint: /bin/cat
args: go.mod
args: go.work

- name: Use env and expression
uses: docker://alpine:latest
Expand Down
18 changes: 16 additions & 2 deletions ghx/executor_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bufio"
"errors"
"fmt"
"path/filepath"
"strings"
Expand Down Expand Up @@ -144,9 +145,12 @@ func (c *ContainerExecutor) Execute(ctx *context.Context) error {

out := strings.TrimSpace(strings.Join([]string{strings.TrimSpace(stdout), strings.TrimSpace(stderr)}, ""))

failed := false

// it seems that dagger no longer returns the stdout or stderr when the container fails. However, same information
// is available in the error message. So, we extract the stdout and stderr from the error message.
if out == "" {
if out == "" && err != nil {
failed = true
out = extractLogFromError(err)
}

Expand All @@ -159,7 +163,17 @@ func (c *ContainerExecutor) Execute(ctx *context.Context) error {
}
}

return efs.Process(ctx)
if err := efs.Process(ctx); err != nil {
return err
}

// if the container failed, return a simple error. Dagger error contains dag information which is not useful for
// the user.
if failed {
return errors.New("step execution encountered an error")
}

return nil
}

// extractLogFromError extracts the stdout and stderr from the error message
Expand Down

0 comments on commit c9b01b3

Please sign in to comment.