From af2e2562494a11ee8e6ede58a29cc250935e74c4 Mon Sep 17 00:00:00 2001 From: Anusha Ragunathan Date: Fri, 23 Sep 2016 11:49:26 -0700 Subject: [PATCH] Return pipeline errors correctly. To use a deferred func to overwrite the returned error requires using the 'named' error. So reuse err, instead of pipelineError. Also, the old pipelineError will never be nil, since its executed before the error can be set. Signed-off-by: Anusha Ragunathan --- pkg/integration/utils.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/integration/utils.go b/pkg/integration/utils.go index b52367d15b..b90bcf1afc 100644 --- a/pkg/integration/utils.go +++ b/pkg/integration/utils.go @@ -68,19 +68,18 @@ func RunCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode in } } - var pipelineError error defer func() { + var pipeErrMsgs []string // wait all cmds except the last to release their resources for _, cmd := range cmds[:len(cmds)-1] { - if err := cmd.Wait(); err != nil { - pipelineError = fmt.Errorf("command %s failed with error: %v", cmd.Path, err) - break + if pipeErr := cmd.Wait(); pipeErr != nil { + pipeErrMsgs = append(pipeErrMsgs, fmt.Sprintf("command %s failed with error: %v", cmd.Path, pipeErr)) } } + if len(pipeErrMsgs) > 0 && err == nil { + err = fmt.Errorf("pipelineError from Wait: %v", strings.Join(pipeErrMsgs, ", ")) + } }() - if pipelineError != nil { - return "", 0, pipelineError - } // wait on last cmd return runCommandWithOutput(cmds[len(cmds)-1])