Skip to content

Commit

Permalink
Use errors.As() (#2074)
Browse files Browse the repository at this point in the history
Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
  • Loading branch information
helsaawy committed Mar 21, 2024
1 parent df34d1d commit def0c29
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/cmd/diag.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func ExecInShimHost(ctx context.Context, req *CmdProcessRequest) (int, error) {
cmd.Stderr = np.Stderr()
err = cmd.Run()
if err != nil {
if exiterr, ok := err.(*exec.ExitError); ok { //nolint:errorlint
if exiterr := (&exec.ExitError{}); errors.As(err, &exiterr) {
return exiterr.ExitCode(), exiterr
}
return -1, err
Expand Down
3 changes: 2 additions & 1 deletion internal/lcow/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package lcow
import (
"bytes"
"context"
"errors"
"fmt"
"time"

Expand All @@ -28,7 +29,7 @@ func formatDiskUvm(ctx context.Context, lcowUVM *uvm.UtilityVM, controller int,
if err == nil {
break
}
if _, ok := err.(*cmdpkg.ExitError); !ok { //nolint:errorlint
if e := (&cmdpkg.ExitError{}); !errors.As(err, &e) {
return fmt.Errorf("failed to run %+v following hot-add %s to utility VM: %w", cmd.Spec.Args, destPath, err)
}
time.Sleep(time.Millisecond * 10)
Expand Down
2 changes: 1 addition & 1 deletion internal/lcow/scratch.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func CreateScratch(ctx context.Context, lcowUVM *uvm.UtilityVM, destFile string,
if err == nil {
break
}
if _, ok := err.(*cmdpkg.ExitError); !ok { //nolint:errorlint
if e := (&cmdpkg.ExitError{}); !errors.As(err, &e) {
return fmt.Errorf("failed to run %+v following hot-add %s to utility VM: %w", cmd.Spec.Args, destFile, err)
}
time.Sleep(time.Millisecond * 10)
Expand Down

0 comments on commit def0c29

Please sign in to comment.