Skip to content

Commit 3e78acd

Browse files
authored
Merge pull request #4168 from AkihiroSuda/fix-4167
print an error that wraps ExitError
2 parents 3c1b994 + db03ff7 commit 3e78acd

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pkg/osutil/exit.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,22 @@
44
package osutil
55

66
import (
7-
"errors"
87
"os"
98
"os/exec"
109
)
1110

11+
// HandleExitError calls os.Exit immediately without printing an error, only if the error is an *exec.ExitError (non-nil).
12+
//
13+
// The function does not call os.Exit if the error is of any other type, even if it wraps an *exec.ExitError,
14+
// so that the caller can print the error message.
1215
func HandleExitError(err error) {
1316
if err == nil {
1417
return
1518
}
1619

17-
var exitErr *exec.ExitError
18-
if errors.As(err, &exitErr) {
20+
// Do not use errors.As, because we want to match only *exec.ExitError, not wrapped ones.
21+
// https://github.com/lima-vm/lima/pull/4168
22+
if exitErr, ok := err.(*exec.ExitError); ok {
1923
os.Exit(exitErr.ExitCode()) //nolint:revive // it's intentional to call os.Exit in this function
2024
return
2125
}

0 commit comments

Comments
 (0)