diff options
| author | Taras Madan <tarasmadan@google.com> | 2023-07-21 11:51:35 +0200 |
|---|---|---|
| committer | Taras Madan <tarasmadan@google.com> | 2023-07-24 09:12:13 +0000 |
| commit | a36fe24b8383f6cd9b3519cd3eabdb9675d8992d (patch) | |
| tree | 3fef9a57760ccc4013289acd60e94e083db466e6 /pkg/osutil | |
| parent | 7549a7e1b57831cf6b08ce4700fc6e53417919f9 (diff) | |
all: use errors.As instead of .(type)
Diffstat (limited to 'pkg/osutil')
| -rw-r--r-- | pkg/osutil/osutil.go | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/pkg/osutil/osutil.go b/pkg/osutil/osutil.go index 1687cef9d..478c091dc 100644 --- a/pkg/osutil/osutil.go +++ b/pkg/osutil/osutil.go @@ -7,6 +7,7 @@ import ( "bytes" "compress/gzip" "context" + "errors" "fmt" "io" "os" @@ -67,7 +68,8 @@ func Run(timeout time.Duration, cmd *exec.Cmd) ([]byte, error) { text = fmt.Sprintf("timedout after %v %q", timeout, cmd.Args) } exitCode := 0 - if exitErr, ok := err.(*exec.ExitError); ok { + var exitErr *exec.ExitError + if errors.As(err, &exitErr) { if status, ok := exitErr.Sys().(syscall.WaitStatus); ok { exitCode = status.ExitStatus() } @@ -120,10 +122,11 @@ func (err *VerboseError) Error() string { } func PrependContext(ctx string, err error) error { - switch err1 := err.(type) { - case *VerboseError: - err1.Title = fmt.Sprintf("%v: %v", ctx, err1.Title) - return err1 + var verboseError *VerboseError + switch { + case errors.As(err, &verboseError): + verboseError.Title = fmt.Sprintf("%v: %v", ctx, verboseError.Title) + return verboseError default: return fmt.Errorf("%v: %w", ctx, err) } |
