Skip to content

Commit ffb0349

Browse files
committed
Update Resolve function to support Is interface
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 <[email protected]>
1 parent 124d0dc commit ffb0349

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

resolve.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,30 @@ func firstError(err error) error {
111111
}
112112
}
113113
return nil
114+
case interface{ Is(error) bool }:
115+
for _, target := range []error{ErrUnknown,
116+
ErrInvalidArgument,
117+
ErrNotFound,
118+
ErrAlreadyExists,
119+
ErrPermissionDenied,
120+
ErrResourceExhausted,
121+
ErrFailedPrecondition,
122+
ErrConflict,
123+
ErrNotModified,
124+
ErrAborted,
125+
ErrOutOfRange,
126+
ErrNotImplemented,
127+
ErrInternal,
128+
ErrUnavailable,
129+
ErrDataLoss,
130+
ErrUnauthenticated,
131+
context.DeadlineExceeded,
132+
context.Canceled} {
133+
if e.Is(target) {
134+
return target
135+
}
136+
}
137+
return nil
114138
default:
115139
return nil
116140
}

0 commit comments

Comments
 (0)