-
Notifications
You must be signed in to change notification settings - Fork 413
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
Use errors.Is for error comparison instead of direct equality checks #502
base: master
Are you sure you want to change the base?
Conversation
|
||
"github.com/ThreeDotsLabs/watermill/message" | ||
|
||
"github.com/ThreeDotsLabs/watermill/message/router/middleware" | ||
"github.com/pkg/errors" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont see a need for this deprecated one
Remove it, so you can use errors directly without an alias
The call to errors.Wrap can be replaced by fmt.Errorf("%w ...")
errors.New can be used directly from stdlib
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like errors.Cause is being used in the current implementation, which makes it a bit more challenging to simply remove the alias.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I had seen before raising my point, errors.Cause is used only in the code, not in the test file I quoted.
But, I have missed something. And I was wrong
There is this indeed.
assert.Equal(t, errFailed, errors.Cause(multierr.WrappedErrors()[1]))
this could be rewritten to use maybe
assert.ErrorIs(t, multierr, errFailed)
Also, maybe it's time to enable some golangci-lint linters https://golangci-lint.run/usage/linters/ err113 is exacly the linter you need for catching what you are fixing. errorlint is a good addition Of course, this could be considered separately from this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to resolve directly my comment, or fix if you want to try.
But for me my comment was a detail, I'm fine with the code.
And thank you for opening the PR
This PR refactors error handling by replacing direct comparisons of errors (e.g., err == someError) with the use of errors.Is.