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

Use errors.Is for error comparison instead of direct equality checks #502

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ytnsym
Copy link

@ytnsym ytnsym commented Oct 14, 2024

This PR refactors error handling by replacing direct comparisons of errors (e.g., err == someError) with the use of errors.Is.


"github.com/ThreeDotsLabs/watermill/message"

"github.com/ThreeDotsLabs/watermill/message/router/middleware"
"github.com/pkg/errors"

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

Copy link
Author

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.

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)

@ccoVeille
Copy link

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

@ytnsym ytnsym requested a review from ccoVeille October 15, 2024 14:07
Copy link

@ccoVeille ccoVeille left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants