Skip to content

Commit

Permalink
Add oops.AsAny, similar to previous oops.As
Browse files Browse the repository at this point in the history
  • Loading branch information
cpl committed Mar 6, 2024
1 parent 3095e6a commit e01d3cf
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/oops/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ func As(err error, target ErrorDefined) (Error, bool) {
return As(v.Unwrap(), target)
}

// AsAny will check if the given err is an Error and if so, return it as an Error.
func AsAny(err error) (Error, bool) {
if err == nil {
return nil, false
}

v, ok := err.(Error)
return v, ok
}

// DeepAs will check if the given err is an Error and if the Error.Source matches the target ErrorDefined, at which
// point err gets returned as an Error. If the given err is not an Error, it will attempt to traverse the unwrap chain
// until an Error is found or nil is reached. Once an Error is found, the check is repeated strictly on Error.Nested
Expand Down

0 comments on commit e01d3cf

Please sign in to comment.