diff --git a/shellwords_test.go b/shellwords_test.go index b32a493..8b3986c 100644 --- a/shellwords_test.go +++ b/shellwords_test.go @@ -1,8 +1,10 @@ package shellwords import ( + "errors" "go/build" "os" + "os/exec" "path" "reflect" "testing" @@ -183,9 +185,9 @@ func TestBacktickError(t *testing.T) { if err == nil { t.Fatal("Should be an error") } - expected := "exit status 2:go Version: unknown command\nRun 'go help' for usage.\n" - if expected != err.Error() { - t.Fatalf("Expected %q, but %q", expected, err.Error()) + var eerr *exec.ExitError + if !errors.As(err, &eerr) { + t.Fatal("Should be able to unwrap to *exec.ExitError") } _, err = parser.Parse(`echo $(echo1)`) if err == nil { diff --git a/util_posix.go b/util_posix.go index 988fc9e..b56a901 100644 --- a/util_posix.go +++ b/util_posix.go @@ -3,7 +3,7 @@ package shellwords import ( - "errors" + "fmt" "os" "os/exec" "strings" @@ -23,7 +23,7 @@ func shellRun(line, dir string) (string, error) { if eerr, ok := err.(*exec.ExitError); ok { b = eerr.Stderr } - return "", errors.New(err.Error() + ":" + string(b)) + return "", fmt.Errorf("%s: %w", string(b), err) } return strings.TrimSpace(string(b)), nil } diff --git a/util_windows.go b/util_windows.go index 2054673..fd738a7 100644 --- a/util_windows.go +++ b/util_windows.go @@ -3,7 +3,7 @@ package shellwords import ( - "errors" + "fmt" "os" "os/exec" "strings" @@ -23,7 +23,7 @@ func shellRun(line, dir string) (string, error) { if eerr, ok := err.(*exec.ExitError); ok { b = eerr.Stderr } - return "", errors.New(err.Error() + ":" + string(b)) + return "", fmt.Errorf("%s: %w", string(b), err) } return strings.TrimSpace(string(b)), nil }