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 2, 2024
1 parent c49707a commit 4c8808b
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 4c8808b

Please sign in to comment.