AsType is a convenience method for checking and getting an error from within a chain that is of type T. If no error is found of type T in the chain the zero value of T is returned with false. If an error in the chain implementes As(any) bool then it's As method will be called if it's type is not of
(err error)
| 394 | // fmt.Println("Failed at path:", pathError.Path) |
| 395 | // } |
| 396 | func AsType[T error](err error) (T, bool) { |
| 397 | for err != nil { |
| 398 | if e, is := err.(T); is { |
| 399 | return e, true |
| 400 | } |
| 401 | var res T |
| 402 | if x, ok := err.(interface{ As(any) bool }); ok && x.As(&res) { |
| 403 | return res, true |
| 404 | } |
| 405 | err = stderrors.Unwrap(err) |
| 406 | } |
| 407 | var zero T |
| 408 | return zero, false |
| 409 | } |
| 410 | |
| 411 | // SetLocation takes a given error and records where in the stack SetLocation |
| 412 | // was called from and returns the wrapped error with the location information |