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
proposal: annotate which error values should never be wrapped #40827
Comments
In addition to documenting which errors should never be wrapped, it would be nice for third-party package authors to know when |
I'm not sure what you mean by annotate here. Do you mean something other than documentation? |
I was intentionally being somewhat vague, as I don't have a strong opinion as to whether that particular bikeshed should be painted red or blue. The goal would be something visible in documentation, as well as consumable by static analysis tools. As a straw man proposal, I think something as simple as an additional method in
This would show up in godoc without changing any method signatures as e.g.
...and I think would be at least partially usable for static analysis. If it returned |
If
(possibly omitting the |
I have code (not involved in implementing I don't think the issue is that In other words, the constraint here is not a property of (For clarity, I'm not necessarily disagreeing with anything here, but making an observation and commenting that there's nothing wrong with wrapping |
I think it's just io.EOF. |
It sounds like it is really just io.EOF. |
Change https://golang.org/cl/258524 mentions this issue: |
Having submitted https://golang.org/cl/258524, is there anything left to propose here? |
For #40827. Change-Id: Ifd108421abd8d0988dd7b985e4f9e2bd5356964a Reviewed-on: https://go-review.googlesource.com/c/go/+/258524 Trust: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
With the io.EOF doc updated, it seems like there is nothing left to do here. This seems like a likely decline. |
No change in consensus, so declined. |
Following up on #39155, I propose there be a consistent method to annotate which error values can never be wrapped, such as
io.EOF
. This would be the first step towards being able to automate detection when illegal wrapping occurs, e.g. causingfmt.Errorf("some message: %w", io.EOF)
to panic, orgo vet
to emit a warning.A naive way to determine this would likely be to grep for
err ==
in the standard library. (Per the above-linked issue, the use of==
instead oferrors.Is()
is a feature, not a bug.) This list should be linked from theerrors
package documentation, and there should be an indication that an error is "not wrappable" in the error value (e.g.io.EOF
) and function (e.g.io.Reader.Read
) documentation.The aim is to detect and prevent incorrect (but reasonable-looking) code such as:
The text was updated successfully, but these errors were encountered: