From 80cc28cbe54cc893e827a9b6122b0c6a7fd27ac4 Mon Sep 17 00:00:00 2001 From: Thomas Miller Date: Tue, 25 Sep 2018 11:59:11 +1000 Subject: [PATCH] Fixes stderr output for failed command actions --- .gitignore | 1 + action/command.go | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 1562c4b..2284db9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ config.json dist disttrust out +testing diff --git a/action/command.go b/action/command.go index 261377a..6ab0c99 100644 --- a/action/command.go +++ b/action/command.go @@ -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 }