Skip to content

Commit

Permalink
Fixes stderr output for failed command actions
Browse files Browse the repository at this point in the history
  • Loading branch information
tlm committed Sep 25, 2018
1 parent 18a75f9 commit 80cc28c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ config.json
dist
disttrust
out
testing
9 changes: 6 additions & 3 deletions action/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ func CommandFromSlice(slice []string) (*Command, error) {

func (c *Command) Fire(ctx context.Context) error {
cmd := exec.CommandContext(ctx, c.slice[0], c.slice[1:]...)
cmd.Stderr = nil
cmd.Stdout = nil
out, err := cmd.Output()
_, err := cmd.Output()

if err != nil {
return fmt.Errorf("command action: %v - %s", err, out)
if exErr, ok := err.(*exec.ExitError); err != nil && ok {
return fmt.Errorf("command action: %v - %s", exErr, exErr.Stderr)
} else if err != nil {
return fmt.Errorf("command action: %v", exErr)
}
return nil
}

0 comments on commit 80cc28c

Please sign in to comment.