Skip to content

Commit

Permalink
fix(CLI): print msg or errors wrapping exec.ExitError
Browse files Browse the repository at this point in the history
  • Loading branch information
mcombuechen committed Apr 26, 2024
1 parent 1a56a0b commit d3f886c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 1 addition & 2 deletions cliv2/cmd/cliv2/main.go
Expand Up @@ -370,8 +370,7 @@ func handleError(err error) HandleError {

func displayError(err error, output io.Writer, config configuration.Configuration) {
if err != nil {
var exitError *exec.ExitError
isExitError := errors.As(err, &exitError)
_, isExitError := err.(*exec.ExitError)
isErrorWithCode := errors.As(err, &cli_errors.ErrorWithExitCode{})
if isExitError || isErrorWithCode {
return
Expand Down
14 changes: 14 additions & 0 deletions cliv2/cmd/cliv2/main_test.go
Expand Up @@ -393,4 +393,18 @@ func Test_displayError(t *testing.T) {
assert.Equal(t, "", b.String())
})
}

t.Run("prints messages of error wrapping exec.ExitError", func(t *testing.T) {
var b bytes.Buffer
config := configuration.NewInMemory()
err := &wrErr{wraps: &exec.ExitError{}}
displayError(err, &b, config)

assert.Equal(t, "something went wrong\n", b.String())
})
}

type wrErr struct{ wraps error }

func (e *wrErr) Error() string { return "something went wrong" }
func (e *wrErr) Unwrap() error { return e.wraps }

0 comments on commit d3f886c

Please sign in to comment.