-
Notifications
You must be signed in to change notification settings - Fork 20.5k
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
chore(all): enable errorlint
and leave error wrapping rule disabled
#31047
Conversation
- Ignore fmt.Errorf not using wrapping with `%w` - Use `errors.Is` instead of `==` - Use `errors.As` instead of direct type assertions
a27f7c2
to
4209f1c
Compare
We don't use Another case where comparing with Certainly, if you can point to a particular piece of code where it would be more sensible to use |
Thanks @fjl for the feedback! 🙏
I understand this, and I very much dislike changing tests as well. However this PR was to pave the way to be able to add production code error wrapping (in forks of go-ethereum for example) and have go-ethereum tests continue passing. Keeping tests as they were mean they would fail as soon as an error would be wrapped in production code.
Certainly, performance sensitive error equality checks should be preserved as Finally, to clarify this "too much checking", and to explain further the full reasoning behind this PR:
We did completely give up on wrapping errors with the fear of one error being equality checked or type asserted directly, causing a subtle change with big consequences. So I have one question left, should I:
|
Can you please let me know which specific errors you would like to wrap in your fork of go-ethereum, so that we can assess where changes will be required? We do use |
Thanks, I will eventually suggest PRs for each single |
Hi there 👋
I understand large scale refactors are a big no-no, but hear me out 🙊 🙏
We, and probably others, use portions of your code. We do like adding context to errors using
fmt.Errorf("some context: %w", err)
to have meaningful and detailed-enough error messages.Unfortunately, there are a lot of places in this codebase using:
err == ErrXYZ
)err.(*ErrXYZ)
)and that prevents wrapping errors with context, since these would fail for a wrapped error.
On the other hand, changing
1.
to useerrors.Is
and2.
to useerrors.As
solve this, and works the same as before as well.Since you already use
golangci-lint
, theerrlint
built-in linter can be enabled to show all the errors regarding the previously mentioned points 1 and 2. The errlint error wrapping rule should be disabled since modifying existing errors to be wrapped is out of scope.All error checks and type assertions are changed to use
errors.Is
anderrors.As
respectively, with theerrlint
linter (partially) enabled.If this is still too much of a large refactor, I'm happy to invest more of my free time into:
errors.Is
and one forerrors.As
Thank you for your reviews!
EDIT: if you don't like this PR at all, please comment why 😉