Skip to content

Commit 3a8853f

Browse files
committed
all: replace calls to errors.As with errors.AsType
This change eliminates the remaining calls to errors.As outside the errors package. CL 708495 purported to eliminate all such calls but missed a few, and a couple had since popped up.
1 parent b28808d commit 3a8853f

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

src/cmd/go/internal/modcmd/vendor.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,10 @@ func vendorPkg(s *modload.State, vdir, pkg string) {
310310
// TODO(#42504): Find a better way to avoid errors from ImportDir. We'll
311311
// need to figure this out when we switch to PackagesAndErrors as per the
312312
// TODO above.
313-
var multiplePackageError *build.MultiplePackageError
314-
var noGoError *build.NoGoError
315313
if err != nil {
316-
if errors.As(err, &noGoError) {
314+
if _, ok := errors.AsType[*build.NoGoError](err); ok {
317315
return // No source files in this package are built. Skip embeds in ignored files.
318-
} else if !errors.As(err, &multiplePackageError) { // multiplePackageErrors are OK, but others are not.
316+
} else if _, ok := errors.AsType[*build.MultiplePackageError](err); !ok { // multiplePackageErrors are OK, but others are not.
319317
base.Fatalf("internal error: failed to find embedded files of %s: %v\n", pkg, err)
320318
}
321319
}

src/encoding/asn1/asn1_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ func TestParsingMemoryConsumption(t *testing.T) {
12411241
Value []byte
12421242
}
12431243
_, err := Unmarshal(derBomb, &out)
1244-
if !errors.As(err, &SyntaxError{}) {
1244+
if _, ok := errors.AsType[SyntaxError](err); !ok {
12451245
t.Fatalf("Incorrect error result: want (%v), but got (%v) instead", &SyntaxError{}, err)
12461246
}
12471247

0 commit comments

Comments
 (0)