46
// ErrorToFailure implements FailureConverter.
47
// nolint:revive // Keeping all of the logic together for readability, even if it means the function is long.
48
>
func (e knownErrorFailureConverter) ErrorToFailure(err error) (nexus.Failure, error) {
failure_converter.go
49
>
if err == nil {
50
return nexus.Failure{}, nil
51
}
52
// NOTE: not using errors.Unwrap here we are intentionally only supporting unwrapping known errors.
55
>
f := typedErr.Failure
56
>
// FailureError is has both a Cause error and an underlying Failure Cause.
57
>
// When instantiated directly, there are cases where only the Go error cause is set.
58
>
// Preserve the embedded failure's cause, as the embedded failure is treated similarly to the OriginalFailure field for well-known other error types.
59
>
if typedErr.Cause != nil && f.Cause == nil {
60
c, err := e.ErrorToFailure(typedErr.Cause)
61
if err != nil {