diff options
| author | Julien Cretel <jub0bsinthecloud@gmail.com> | 2025-09-29 16:57:53 +0000 |
|---|---|---|
| committer | Damien Neil <dneil@google.com> | 2025-09-30 10:22:08 -0700 |
| commit | a846bb0aa523c8781248161b63bc2ab6a245cec1 (patch) | |
| tree | c43a403c0e8fde2fd9c6019428cddc74710cf4e5 /src/errors/errors.go | |
| parent | 7c8166d02d36a5dfcdbe3dd1b148412cceacf9f2 (diff) | |
| download | go-a846bb0aa523c8781248161b63bc2ab6a245cec1.tar.xz | |
errors: add AsType
Fixes #51945
Change-Id: Icda169782e796578eba728938134a85b5827d3b6
GitHub-Last-Rev: c6ff335ee1ffb6b7975141795a4632a55247299d
GitHub-Pull-Request: golang/go#75621
Reviewed-on: https://go-review.googlesource.com/c/go/+/707235
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Sean Liao <sean@liao.dev>
Diffstat (limited to 'src/errors/errors.go')
| -rw-r--r-- | src/errors/errors.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/errors/errors.go b/src/errors/errors.go index 5059be12ed..8b926cfe14 100644 --- a/src/errors/errors.go +++ b/src/errors/errors.go @@ -41,12 +41,12 @@ // // because the former will succeed if err wraps [io/fs.ErrExist]. // -// [As] examines the tree of its first argument looking for an error that can be -// assigned to its second argument, which must be a pointer. If it succeeds, it -// performs the assignment and returns true. Otherwise, it returns false. The form +// [AsType] examines the tree of its argument looking for an error whose +// type matches its type argument. If it succeeds, it returns the +// corresponding value of that type and true. Otherwise, it returns the +// zero value of that type and false. The form // -// var perr *fs.PathError -// if errors.As(err, &perr) { +// if perr, ok := errors.AsType[*fs.PathError](err); ok { // fmt.Println(perr.Path) // } // |
