Skip to content

Commit cb52c53

Browse files
authored
refactor: use errors.AsType (#510)
Replaces use of `errors.As` with `errors.AsType`, a generic function introduced in Go 1.26 that unwraps errors in a type-safe way and returns a typed result directly. Instead of declaring a separate variable and passing a pointer to it, `errors.AsType` returns a typed result directly. This makes the code shorter, easier to read, and avoids common mistakes related to incorrect pointer usage. Signed-off-by: Ryan Johnson <ryan@tenthirtyam.org>
1 parent 8264fb1 commit cb52c53

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

builder/vmware/common/driver.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,7 @@ func runAndLog(cmd *exec.Cmd) (string, string, error) {
380380
stdoutString := strings.TrimSpace(stdout.String())
381381
stderrString := strings.TrimSpace(stderr.String())
382382

383-
var exitError *exec.ExitError
384-
if errors.As(err, &exitError) {
383+
if _, ok := errors.AsType[*exec.ExitError](err); ok {
385384
message := stderrString
386385
if message == "" {
387386
message = stdoutString

0 commit comments

Comments
 (0)