From 5d5ca0d3c40c2b1ca90931af18e6c8a71e08209e Mon Sep 17 00:00:00 2001 From: Harry White Date: Mon, 28 Oct 2019 22:17:28 +1100 Subject: [PATCH 1/2] Return only stdout from command docker-compose outputs warning messages to stderr --- pkg/commands/os.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/commands/os.go b/pkg/commands/os.go index d5a09914..b2fd42ec 100644 --- a/pkg/commands/os.go +++ b/pkg/commands/os.go @@ -60,7 +60,7 @@ func (c *OSCommand) SetCommand(cmd func(string, ...string) *exec.Cmd) { func (c *OSCommand) RunCommandWithOutput(command string) (string, error) { cmd := c.ExecutableFromString(command) before := time.Now() - output, err := sanitisedCommandOutput(cmd.CombinedOutput()) + output, err := sanitisedCommandOutput(cmd.Output()) c.Log.Warn(fmt.Sprintf("'%s': %s", command, time.Since(before))) return output, err } From b22b4801affac6acf61ade62b465392c6f09e93d Mon Sep 17 00:00:00 2001 From: Harry White Date: Mon, 28 Oct 2019 22:45:37 +1100 Subject: [PATCH 2/2] Return error with stderr value To maintain existing behaviour when not capturing stdout and stderr --- pkg/commands/os.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/commands/os.go b/pkg/commands/os.go index b2fd42ec..22490b49 100644 --- a/pkg/commands/os.go +++ b/pkg/commands/os.go @@ -115,11 +115,12 @@ func sanitisedCommandOutput(output []byte, err error) (string, error) { outputString := string(output) if err != nil { // errors like 'exit status 1' are not very useful so we'll create an error - // from the combined output - if outputString == "" { - return "", WrapError(err) + // from stderr if we got an ExitError + exitError, ok := err.(*exec.ExitError) + if ok { + return outputString, errors.New(string(exitError.Stderr)) } - return outputString, errors.New(outputString) + return "", WrapError(err) } return outputString, nil }