Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pkg/osutil/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down