-
Notifications
You must be signed in to change notification settings - Fork 8
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
doc: update error-compare and define unwrapped-error #162
Conversation
Pull Request Test Coverage Report for Build 9732834377Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9732886433Details
💛 - Coveralls |
ErrorContains is anti-pattern and, I think, must be flagged by default. We can consider an option (config) to turn off it or vice versa |
Do you agree that
Shall be converted to
Then there can be another |
Pull Request Test Coverage Report for Build 9733131811Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9733147710Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9733219903Details
💛 - Coveralls |
@ccoVeille , |
CONTRIBUTING.md
Outdated
|
||
**Autofix**: true. <br> | ||
**Enabled by default**: true. <br> | ||
**Reason**: The `Error()` method on the `error` interface exists for humans, not code. <br> |
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.
Using testify methods are error prone as they avoid nil pointer exception.
Pull Request Test Coverage Report for Build 9748055669Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9748065672Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9748225491Warning: This coverage report may be inaccurate.This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.
Details
💛 - Coveralls |
9d3bc59
to
9e6e06b
Compare
Pull Request Test Coverage Report for Build 9748271183Details
💛 - Coveralls |
assert.Equal(t, err.Error(), "user not found") | ||
assert.Equal(t, err, errSentinel) // Through `reflect.DeepEqual` causes error strings to be compared. | ||
assert.NotEqual(t, err, errSentinel) | ||
// etc. | ||
|
||
✅ assert.ErrorContains(t, err, "not found") | ||
assert.EqualError(t, err, "user not found") |
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'm a bit afraid this one is valid
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.
You probably need a rule that says
If I have
var ErrUserNotFound = errors.New("user not found")
...
assert.EqualError(t, err, "user not found")
Then you shall replace it with
var ErrUserNotFound = errors.New("user not found")
...
assert.ErrorIs(t, err, ErrUserNotFound)
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.
My point is that ErrorEqual should be part of the same checker than ErrorContains.
It should be discouraged
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.
Ok, we probably need to change namings then . Maybe error-compare for those two and something else for the use of Error()
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.
Maybe, let's wait for Anton's feedback
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.
@Antonboom maybe you missed this old thread
You said ErrorContains is an antipattern, what is your point of view about ErrorEqual ?
Pull Request Test Coverage Report for Build 9759437884Details
💛 - Coveralls |
Pull Request Test Coverage Report for Build 9759450840Details
💛 - Coveralls |
These names make more sense 👍 |
9ae9d09
to
a209c77
Compare
Pull Request Test Coverage Report for Build 9826241707Details
💛 - Coveralls |
a209c77
to
e1e5f54
Compare
Pull Request Test Coverage Report for Build 10704183307Details
💛 - Coveralls |
Co-authored-by: ccoVeille <[email protected]>
e1e5f54
to
4cb531e
Compare
Following the different exchanges about error compare, I believe testifylint shall be allowed to recommend the use of ErrorContains, ErrorEqual, ErrorIs and NotErrorIs.
See #47 (comment) for more context
I believe ErrorIs is only applicable to wrapped errors but I might be missing something.