Skip to content

Commit

Permalink
Update Resolve function to support Is interface
Browse files Browse the repository at this point in the history
The Is interface may be used to resolve if no other unwrap interface is
implemented. This interface is safe to use in this situation, unlike
errors.Is, since the error should not be unwrapped further.

Signed-off-by: Derek McGowan <derek@mcg.dev>
  • Loading branch information
dmcgowan committed Jul 10, 2024
1 parent 124d0dc commit ffb0349
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,30 @@ func firstError(err error) error {
}
}
return nil
case interface{ Is(error) bool }:
for _, target := range []error{ErrUnknown,
ErrInvalidArgument,
ErrNotFound,
ErrAlreadyExists,
ErrPermissionDenied,
ErrResourceExhausted,
ErrFailedPrecondition,
ErrConflict,
ErrNotModified,
ErrAborted,
ErrOutOfRange,
ErrNotImplemented,
ErrInternal,
ErrUnavailable,
ErrDataLoss,
ErrUnauthenticated,
context.DeadlineExceeded,
context.Canceled} {
if e.Is(target) {
return target
}
}
return nil
default:
return nil
}
Expand Down

0 comments on commit ffb0349

Please sign in to comment.