Skip to content

Commit 006c40f

Browse files
committed
print an error that wraps ExitError
Fix issue 4167 Signed-off-by: Akihiro Suda <[email protected]>
1 parent 586e995 commit 006c40f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pkg/osutil/exit.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,23 @@
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.
15+
// (i.e., fmt.Errorf("...: %w", &exec.ExitError{}))
1216
func HandleExitError(err error) {
1317
if err == nil {
1418
return
1519
}
1620

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

0 commit comments

Comments
 (0)