all: replace calls to errors.As with errors.AsType

This change replaces most occurrences (in code as well as in comments) of
errors.As with errors.AsType. It leaves the errors package and vendored
code untouched.

Change-Id: I3bde73f318a0b408bdb8f5a251494af15a13118a
GitHub-Last-Rev: 8aaaa36
GitHub-Pull-Request: #75698
Reviewed-on: https://go-review.googlesource.com/c/go/+/708495
Auto-Submit: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
This commit is contained in:
yuhan6665
2026-09-08 21:33:46 -04:00
parent b21b05ff92
commit 5bfa940c97
3 changed files with 7 additions and 9 deletions
+2 -2
View File
@@ -1645,9 +1645,9 @@ func (c *Conn) handshakeContext(ctx context.Context) (ret error) {
// the handshake (RFC 9001, Section 5.7).
c.quicSetReadSecret(QUICEncryptionLevelApplication, c.cipherSuite, c.in.trafficSecret)
} else {
var a alert
c.out.Lock()
if !errors.As(c.out.err, &a) {
a, ok := errors.AsType[alert](c.out.err)
if !ok {
a = alertInternalError
}
c.out.Unlock()
+2 -3
View File
@@ -948,10 +948,9 @@ func (c *Conn) processCertsFromClient(certificate Certificate) error {
chains, err := certs[0].Verify(opts)
if err != nil {
var errCertificateInvalid x509.CertificateInvalidError
if errors.As(err, &x509.UnknownAuthorityError{}) {
if _, ok := errors.AsType[x509.UnknownAuthorityError](err); ok {
c.sendAlert(alertUnknownCA)
} else if errors.As(err, &errCertificateInvalid) && errCertificateInvalid.Reason == x509.Expired {
} else if errCertificateInvalid, ok := errors.AsType[x509.CertificateInvalidError](err); ok && errCertificateInvalid.Reason == x509.Expired {
c.sendAlert(alertCertificateExpired)
} else {
c.sendAlert(alertBadCertificate)
+3 -4
View File
@@ -363,12 +363,11 @@ func quicError(err error) error {
if err == nil {
return nil
}
var ae AlertError
if errors.As(err, &ae) {
if _, ok := errors.AsType[AlertError](err); ok {
return err
}
var a alert
if !errors.As(err, &a) {
a, ok := errors.AsType[alert](err)
if !ok {
a = alertInternalError
}
// Return an error wrapping the original error and an AlertError.