diff --git a/pkg/downloader/downloader.go b/pkg/downloader/downloader.go index 9cf78e23..4331add9 100644 --- a/pkg/downloader/downloader.go +++ b/pkg/downloader/downloader.go @@ -786,8 +786,7 @@ func decompressLocal(ctx context.Context, decompressCmd, dst, src, ext, descript cmd.Stderr = buf err = cmd.Run() if err != nil { - var exitErr *exec.ExitError - if errors.As(err, &exitErr) { + if exitErr, ok := errors.AsType[*exec.ExitError](err); ok { exitErr.Stderr = buf.Bytes() } } diff --git a/pkg/hostagent/api/client/client.go b/pkg/hostagent/api/client/client.go index e1e7ee36..e9cb93fe 100644 --- a/pkg/hostagent/api/client/client.go +++ b/pkg/hostagent/api/client/client.go @@ -82,8 +82,7 @@ func (c *client) Screenshot(ctx context.Context, format string) ([]byte, error) u := fmt.Sprintf("http://%s/%s/screenshot?%s", c.dummyHost, c.version, params.Encode()) resp, err := httpclientutil.Get(ctx, c.HTTPClient(), u) if err != nil { - var httpErr *httpclientutil.HTTPStatusError - if errors.As(err, &httpErr) { + if httpErr, ok := errors.AsType[*httpclientutil.HTTPStatusError](err); ok { switch httpErr.StatusCode { case http.StatusNotFound: return nil, errors.New("hostagent does not support screenshot — restart the instance to pick up the latest hostagent binary") diff --git a/pkg/limatmpl/locator.go b/pkg/limatmpl/locator.go index e391ec06..a95219c2 100644 --- a/pkg/limatmpl/locator.go +++ b/pkg/limatmpl/locator.go @@ -376,8 +376,7 @@ func transformCustomURL(ctx context.Context, locator string) (string, error) { stdout, err := cmd.Output() if err != nil { - var exitErr *exec.ExitError - if errors.As(err, &exitErr) { + if exitErr, ok := errors.AsType[*exec.ExitError](err); ok { stderrMsg := string(exitErr.Stderr) if stderrMsg != "" { return "", fmt.Errorf("command %#q failed: %s", cmd.String(), strings.TrimSpace(stderrMsg)) diff --git a/pkg/networks/reconcile/reconcile.go b/pkg/networks/reconcile/reconcile.go index 7dc0bf4f..989c7150 100644 --- a/pkg/networks/reconcile/reconcile.go +++ b/pkg/networks/reconcile/reconcile.go @@ -305,12 +305,10 @@ func startDaemonWithRetry(ctx context.Context, cfg *networks.Config, name, daemo } // Only an early exit (the transient XPC race) is retried; everything else // is surfaced immediately. - var exited *daemonExitedError - if !errors.As(err, &exited) { + if _, ok := errors.AsType[*daemonExitedError](err); !ok { // A stuck (still-running) daemon gets its stderr appended; PID-read and // context errors propagate as-is. - var stuck *daemonStuckError - if errors.As(err, &stuck) { + if _, ok := errors.AsType[*daemonStuckError](err); ok { return fmt.Errorf("%s daemon for %#q network %w%s", daemon, name, err, stderrHint(stderrLog)) } return err