Sadly the go 2/1.13 design for errors has promoted the name `Unwrap()` for the method that accesses the cause, whilst the ecosystem has already chosen `Cause()`. In order to unwrap reliably, we must thus support both. See: https://github.com/golang/go/issues/31778 UnwrapOnce accesses the direct cau
(err error)
| 38 | // The go stdlib does not define output on `Unwrap()` for a multi-cause |
| 39 | // error, so we default to nil here. |
| 40 | func UnwrapOnce(err error) (cause error) { |
| 41 | switch e := err.(type) { |
| 42 | case interface{ Cause() error }: |
| 43 | return e.Cause() |
| 44 | case interface{ Unwrap() error }: |
| 45 | return e.Unwrap() |
| 46 | } |
| 47 | return nil |
| 48 | } |
| 49 | |
| 50 | // UnwrapAll accesses the root cause object of the error. |
| 51 | // If the error has no cause (leaf error), it is returned directly. |
searching dependent graphs…