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

doc: update error-compare and define unwrapped-error #162

Closed

Conversation

mmorel-35
Copy link

@mmorel-35 mmorel-35 commented Jun 30, 2024

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.

@coveralls
Copy link

coveralls commented Jun 30, 2024

Pull Request Test Coverage Report for Build 9732834377

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 93.692%

Totals Coverage Status
Change from base Build 9673069496: 0.0%
Covered Lines: 2213
Relevant Lines: 2362

💛 - Coveralls

@mmorel-35 mmorel-35 changed the title error-compare: allow ErrorContains and ErrorEqual error-compare (doc): allow ErrorContains and ErrorEqual Jun 30, 2024
@mmorel-35 mmorel-35 changed the title error-compare (doc): allow ErrorContains and ErrorEqual error-compare (doc): allow ErrorContains and EqualError Jun 30, 2024
@mmorel-35 mmorel-35 changed the title error-compare (doc): allow ErrorContains and EqualError error-compare (doc): allow more error methods Jun 30, 2024
@coveralls
Copy link

coveralls commented Jun 30, 2024

Pull Request Test Coverage Report for Build 9732886433

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 93.692%

Totals Coverage Status
Change from base Build 9673069496: 0.0%
Covered Lines: 2213
Relevant Lines: 2362

💛 - Coveralls

@Antonboom
Copy link
Owner

Antonboom commented Jun 30, 2024

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

@Antonboom Antonboom added the documentation Improvements or additions to documentation label Jun 30, 2024
@mmorel-35
Copy link
Author

Do you agree that

assert.Contains(t, err.Error(), "not found")

Shall be converted to

assert.ErrorContains(t, err, "not found")

Then there can be another error-contains
That would not be fixable by default saying
Use ErrorIs on a known error or something

@coveralls
Copy link

coveralls commented Jun 30, 2024

Pull Request Test Coverage Report for Build 9733131811

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 93.692%

Totals Coverage Status
Change from base Build 9673069496: 0.0%
Covered Lines: 2213
Relevant Lines: 2362

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jun 30, 2024

Pull Request Test Coverage Report for Build 9733147710

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 93.692%

Totals Coverage Status
Change from base Build 9673069496: 0.0%
Covered Lines: 2213
Relevant Lines: 2362

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jun 30, 2024

Pull Request Test Coverage Report for Build 9733219903

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 93.692%

Totals Coverage Status
Change from base Build 9673069496: 0.0%
Covered Lines: 2213
Relevant Lines: 2362

💛 - Coveralls

@mmorel-35
Copy link
Author

@ccoVeille ,
Any suggestions to improve "reason" paragraph for error-contains ?

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>
Copy link
Contributor

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.

@coveralls
Copy link

coveralls commented Jul 1, 2024

Pull Request Test Coverage Report for Build 9748055669

Warning: 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

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 93.692%

Totals Coverage Status
Change from base Build 9673069496: 0.0%
Covered Lines: 2213
Relevant Lines: 2362

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jul 1, 2024

Pull Request Test Coverage Report for Build 9748065672

Warning: 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

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 93.692%

Totals Coverage Status
Change from base Build 9673069496: 0.0%
Covered Lines: 2213
Relevant Lines: 2362

💛 - Coveralls

CONTRIBUTING.md Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Jul 1, 2024

Pull Request Test Coverage Report for Build 9748225491

Warning: 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

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 93.692%

Totals Coverage Status
Change from base Build 9673069496: 0.0%
Covered Lines: 2213
Relevant Lines: 2362

💛 - Coveralls

@coveralls
Copy link

coveralls commented Jul 1, 2024

Pull Request Test Coverage Report for Build 9748271183

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 93.692%

Totals Coverage Status
Change from base Build 9743211634: 0.0%
Covered Lines: 2213
Relevant Lines: 2362

💛 - Coveralls

@mmorel-35 mmorel-35 changed the title error-compare (doc): allow more error methods doc: update error-compare and define error-contains Jul 1, 2024
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")
Copy link
Contributor

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

Copy link
Author

@mmorel-35 mmorel-35 Jul 1, 2024

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)

Copy link
Contributor

@ccoVeille ccoVeille Jul 1, 2024

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

Copy link
Author

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()

Copy link
Contributor

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

Copy link
Contributor

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

4cb531e#r1661489366

You said ErrorContains is an antipattern, what is your point of view about ErrorEqual ?

@coveralls
Copy link

coveralls commented Jul 2, 2024

Pull Request Test Coverage Report for Build 9759437884

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 93.692%

Totals Coverage Status
Change from base Build 9743211634: 0.0%
Covered Lines: 2213
Relevant Lines: 2362

💛 - Coveralls

@mmorel-35 mmorel-35 changed the title doc: update error-compare and define error-contains doc: update error-compare and define unwrapped-error Jul 2, 2024
@coveralls
Copy link

coveralls commented Jul 2, 2024

Pull Request Test Coverage Report for Build 9759450840

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 93.692%

Totals Coverage Status
Change from base Build 9743211634: 0.0%
Covered Lines: 2213
Relevant Lines: 2362

💛 - Coveralls

@ccoVeille
Copy link
Contributor

These names make more sense 👍

@coveralls
Copy link

coveralls commented Jul 7, 2024

Pull Request Test Coverage Report for Build 9826241707

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 93.692%

Totals Coverage Status
Change from base Build 9743211634: 0.0%
Covered Lines: 2213
Relevant Lines: 2362

💛 - Coveralls

@coveralls
Copy link

coveralls commented Aug 29, 2024

Pull Request Test Coverage Report for Build 10704183307

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 93.689%

Totals Coverage Status
Change from base Build 10661004539: 0.0%
Covered Lines: 2212
Relevant Lines: 2361

💛 - Coveralls

@mmorel-35 mmorel-35 closed this by deleting the head repository Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants