-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
x/tools/go/analysis: show invalid usage of errors.As() #61342
Comments
There is A different way to fix the issue in the example program is
It's hard to tell if it's a misuse or not without know how |
The mistake, I think, is here:
CustomError{...} is an error value, and &CustomError{} is a pointer that also happens to implement the error interface but isn't how this type is supposed to be used. One possibility is to change the printf checker to report %w applied to a value of type *E where E implements error. That would be something we could easily evaluate using the new metrics pipeline. @timothy-king |
Wow, this would be great. If you are new to Go, then a warning in the IDE would really help. Thank you. |
Just to clarify
Once I am back, I can look at this pretty quickly. It would be good to have data. |
Is your feature request related to a problem? Please describe.
This fails:
Describe the solution you'd like
I would like to get a warning if I provide a pointer to a struct to errors.As().
Changing the line to this works:
That's easy to get wrong, and it takes some time to find the error.
Describe alternatives you've considered
I considered the alternative: don't make mistakes. But sorry, I am not perfect.
The text was updated successfully, but these errors were encountered: