MCPcopy Create free account
hub / github.com/juju/errors / AsType

Function AsType

functions.go:396–409  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

394// fmt.Println("Failed at path:", pathError.Path)
395// }
396func 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

Callers

nothing calls this directly

Calls 2

AsMethod · 0.80
UnwrapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…