Skip to content

Commit

Permalink
Use sterr from exitError in error message as a fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
lpusok committed May 21, 2024
1 parent 613f4cb commit f2dde89
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions command/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ type ExitStatusError struct {
// NewExitStatusError ...
func NewExitStatusError(printableCmdArgs string, exitErr *exec.ExitError, errorLines []string) error {
reasonMsg := fmt.Sprintf("command failed with exit status %d (%s)", exitErr.ExitCode(), printableCmdArgs)
if len(errorLines) == 0 {
return &ExitStatusError{
readableReason: fmt.Errorf("%s: %w", reasonMsg, errors.New("check the command's output for details")),
originalExitErr: exitErr,
}

errorOutput := strings.Join(errorLines, "\n")
if len(errorOutput) == 0 && len(exitErr.Stderr) != 0 {
errorOutput = string(exitErr.Stderr)
}
if len(errorOutput) == 0 {
errorOutput = "check the command's output for details"
}

return &ExitStatusError{
readableReason: fmt.Errorf("%s: %w", reasonMsg, errors.New(strings.Join(errorLines, "\n"))),
readableReason: fmt.Errorf("%s: %w", reasonMsg, errors.New(errorOutput)),
originalExitErr: exitErr,
}
}
Expand Down

0 comments on commit f2dde89

Please sign in to comment.