Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 5 additions & 9 deletions cmd/limactl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func main() {
rootCmd := newApp()
if err := executeWithPluginSupport(rootCmd, os.Args[1:]); err != nil {
server.StopAllExternalDrivers()
handleExitCoder(err)
handleExitError(err)
logrus.Fatal(err)
}

Expand Down Expand Up @@ -200,17 +200,13 @@ func newApp() *cobra.Command {
return rootCmd
}

type ExitCoder interface {
error
ExitCode() int
}

func handleExitCoder(err error) {
func handleExitError(err error) {
if err == nil {
return
}

if exitErr, ok := err.(ExitCoder); ok {
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
os.Exit(exitErr.ExitCode()) //nolint:revive // it's intentional to call os.Exit in this function
return
}
Expand Down Expand Up @@ -253,7 +249,7 @@ func runExternalPlugin(ctx context.Context, name string, args []string) {
cmd.Env = os.Environ()

err = cmd.Run()
handleExitCoder(err)
handleExitError(err)
if err == nil {
os.Exit(0) //nolint:revive // it's intentional to call os.Exit in this function
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,9 @@ func decompressLocal(ctx context.Context, decompressCmd, dst, src, ext, descript
bar.Start()
err = cmd.Run()
if err != nil {
if ee, ok := err.(*exec.ExitError); ok {
ee.Stderr = buf.Bytes()
var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
exitErr.Stderr = buf.Bytes()
}
}
bar.Finish()
Expand Down
3 changes: 2 additions & 1 deletion pkg/networks/usernet/udpfileconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ type UDPFileConn struct {
func (conn *UDPFileConn) Read(b []byte) (n int, err error) {
// Check if the connection has been closed
if err := conn.SetReadDeadline(time.Time{}); err != nil {
if opErr, ok := err.(*net.OpError); ok && opErr.Err.Error() == "use of closed network connection" {
var opErr *net.OpError
if errors.As(err, &opErr) && opErr.Err.Error() == "use of closed network connection" {
return 0, errors.New("UDPFileConn connection closed")
}
}
Expand Down
Loading