Skip to content

Commit

Permalink
Catch command pipeline error.
Browse files Browse the repository at this point in the history
Rather than ignoring errors in the pipeline, return an execution error
and do not proceed with the latest command in the pipeline.

Signed-off-by: David Calavera <[email protected]>
  • Loading branch information
calavera committed Dec 22, 2015
1 parent 81c8e4d commit f382573
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/integration/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,19 @@ func RunCommandPipelineWithOutput(cmds ...*exec.Cmd) (output string, exitCode in
}
}

var pipelineError error
defer func() {
// wait all cmds except the last to release their resources
for _, cmd := range cmds[:len(cmds)-1] {
cmd.Wait()
if err := cmd.Wait(); err != nil {
pipelineError = fmt.Errorf("command %s failed with error: %v", cmd.Path, err)
break
}
}
}()
if pipelineError != nil {
return "", 0, pipelineError
}

// wait on last cmd
return RunCommandWithOutput(cmds[len(cmds)-1])
Expand Down

0 comments on commit f382573

Please sign in to comment.