Skip to content
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

Remove unwrapping in error Is methods #2269

Merged
merged 3 commits into from
Aug 3, 2023

Conversation

triarius
Copy link
Contributor

@triarius triarius commented Aug 3, 2023

I was doing some "light reading" of the go standard library, and noticed this:

// ... An Is method should only shallowly
// compare err and the target and not call Unwrap on either.

In the former implementations, calling errors.As could unwrap the errors, so this PR fixes this.

@triarius triarius marked this pull request as ready for review August 3, 2023 06:03
@triarius triarius requested a review from a team August 3, 2023 06:03
Copy link
Contributor

Choose a reason for hiding this comment

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

While we're here, you could update Errors to be Unwrap that returns []error. I don't think any call sites of Errors use anything other than the Error method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@DrJosh9000 DrJosh9000 left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM!

@triarius triarius force-pushed the pdp-1424-fix-error-is-method-unwraps branch from d0f5c92 to 2ee34ab Compare August 3, 2023 07:21
Comment on lines +43 to +46
out := make([]error, 0, len(errs))
for i := range errs {
out = append(out, &errs[i])
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the alternative is to make errs have type []error, then type-assert everything in the sort.Slice closure...

Hang on, does anything use the order of e.errs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's nice for the user. I wrote tests for it, so they will break

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm. Maybe I didn't 🤷‍♂️. Still think it's nice for the user.

@triarius triarius merged commit ead9ebc into main Aug 3, 2023
1 check passed
@triarius triarius deleted the pdp-1424-fix-error-is-method-unwraps branch August 3, 2023 23:23
@DrJosh9000 DrJosh9000 added the cleanup Cleaning up code, refactoring, etc label Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Cleaning up code, refactoring, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants