-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathstdlib_go18.go
More file actions
20 lines (19 loc) · 872 Bytes
/
stdlib_go18.go
File metadata and controls
20 lines (19 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package errors
// AsType finds the first error in err's tree that matches the type E, and
// if one is found, returns that error value and true. Otherwise, it
// returns the zero value of E and false.
//
// The tree consists of err itself, followed by the errors obtained by
// repeatedly calling its Unwrap() error or Unwrap() []error method. When
// err wraps multiple errors, AsType examines err followed by a
// depth-first traversal of its children.
//
// An error err matches the type E if the type assertion err.(E) holds,
// or if the error has a method As(any) bool such that err.As(target)
// returns true when target is a non-nil *E. In the latter case, the As
// method is responsible for setting target.
//
// This function is a proxy for standard errors.AsType.
func AsType[E error](err error) (E, bool) { //nolint:ireturn
return stderrorsAsType[E](err)
}