diff --git a/cmd/limactl/main.go b/cmd/limactl/main.go index 22aa916ab49..e0e0723bafa 100644 --- a/cmd/limactl/main.go +++ b/cmd/limactl/main.go @@ -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) } @@ -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 } @@ -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 } diff --git a/pkg/downloader/downloader.go b/pkg/downloader/downloader.go index bfb73776020..71101981d4b 100644 --- a/pkg/downloader/downloader.go +++ b/pkg/downloader/downloader.go @@ -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() diff --git a/pkg/networks/usernet/udpfileconn.go b/pkg/networks/usernet/udpfileconn.go index 96b64e3d8ad..ef04b841e5d 100644 --- a/pkg/networks/usernet/udpfileconn.go +++ b/pkg/networks/usernet/udpfileconn.go @@ -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") } }