lint: fix errorsastype: errors.As can be simplified using AsType[...]

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
Akihiro Suda committed 2026-08-24 10:29:50 +09:00
1 parent baf8e947a3
commit b7eaa66212
4 files changed
+5 -10

No files matched your search

+1 -2
View File
@@ -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()
}
}
+1 -2
View File
@@ -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")
+1 -2
View File
@@ -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))
+2 -4
View File
@@ -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