-
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
error-compare: detect contains of err.Error() #47
Comments
Hi! Thank you for feedback. |
I see that Some justification I can think of for using |
For records, I started working on the implementation of this feature request. https://github.com/Antonboom/testifylint/blob/master/CONTRIBUTING.md#error-compare Stay tuned, and ping me if you see no progress in the next month. |
I agree with @Limero @nickajacks1 there is a need for a checker that will look for detecting this.
This should be a checker activated by default. As @Antonboom said, there is a need for a checker these by .ErrorContains(t, err, ErrSentinel) But these are two separate needs. While the first one is legitimate and should be activated by default. The second one is more opinionated and could lead to problems. We have to consider ErrorContains could be used for wrapped error to check one word is present in the error message Let's consider a code returning that fmt.Errorf("error %w - code %s, ErrSentinel, "foo") I would use assert.ErrorIs(t, err, ErrSentinel) but then I would use assert.ErrorContains(t, err, "foo") These use cases are legitimate. But I agree we should also prevent the following pattern and suggest to use Error.Is
This is pattern was sometimes used before testify.Error.Is and even errors.Is existed in standard lib. |
I have found this: A comparison of errors messages |
The complexity involved in this is insane 😁 |
Shall there be a translator asking to use err.Error() Instead of fmt.Sprintf("%v", err) Then unwrapped-error can be applied |
Yes, I also found https://github.com/search?q=language%3Ago+%22fmt.Sprint%28err%29%22+testify&type=code assert.Contains(t, fmt.Sprint(err), "no project token(s) found for provided projects") |
Running
testifylint
on a large codebase at work I noticed that people sometimes useContains
to check error messages, something thattestifylint
currently doesn't detectExpected results:
The text was updated successfully, but these errors were encountered: