Skip to content

🌱 Enable using errors.Is with ErrResourceDiscoveryFailed error #2935

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/client/apiutil/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@ func (e *ErrResourceDiscoveryFailed) Unwrap() []error {
}
return subErrors
}

// Is makes it possible for the callers to use `errors.Is(` helper on errors wrapped with ErrResourceDiscoveryFailed error.
func (e *ErrResourceDiscoveryFailed) Is(target error) bool {
_, ok := target.(*ErrResourceDiscoveryFailed)
return ok
Comment on lines +58 to +59
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_, ok := target.(*ErrResourceDiscoveryFailed)
return ok
ep := &ErrResourceDiscoveryFailed{}
return errors.As(target,ep)

We have done this for Terminal error in pkg/reconcile/reconcile.go:179

func (te *terminalError) Is(target error) bool {
tp := &terminalError{}
return errors.As(target, &tp)
}

I am not sure if this is needed but I would add a test if you are adding this change.

Copy link
Contributor Author

@tamalsaha tamalsaha Aug 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-08-29 at 1 06 35 PM

I don't think Is should be implemented using As, since As calls unwrap.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't matter, if the Is implementation doesn't call unwrap, errors.Is does, so the result is the same. Please add a test though.

}