From 4c8808b9f383202050169e6b189e8c0d6cb346a1 Mon Sep 17 00:00:00 2001 From: Derek McGowan Date: Tue, 2 Jul 2024 16:16:36 -0700 Subject: [PATCH] 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 --- resolve.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/resolve.go b/resolve.go index ea049da..852d591 100644 --- a/resolve.go +++ b/resolve.go @@ -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 }