From db03ff7ff3ba5d2a241db10b7fabc5f7d8753132 Mon Sep 17 00:00:00 2001 From: Akihiro Suda Date: Thu, 9 Oct 2025 16:13:35 +0900 Subject: [PATCH] print an error that wraps ExitError Fix issue 4167 Signed-off-by: Akihiro Suda --- pkg/osutil/exit.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/osutil/exit.go b/pkg/osutil/exit.go index ee14ecc20d2..588f1d00d44 100644 --- a/pkg/osutil/exit.go +++ b/pkg/osutil/exit.go @@ -4,18 +4,22 @@ package osutil import ( - "errors" "os" "os/exec" ) +// HandleExitError calls os.Exit immediately without printing an error, only if the error is an *exec.ExitError (non-nil). +// +// The function does not call os.Exit if the error is of any other type, even if it wraps an *exec.ExitError, +// so that the caller can print the error message. func HandleExitError(err error) { if err == nil { return } - var exitErr *exec.ExitError - if errors.As(err, &exitErr) { + // Do not use errors.As, because we want to match only *exec.ExitError, not wrapped ones. + // https://github.com/lima-vm/lima/pull/4168 + if exitErr, ok := err.(*exec.ExitError); ok { os.Exit(exitErr.ExitCode()) //nolint:revive // it's intentional to call os.Exit in this function return }