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
errors: how should formatting be handled? #35929
Comments
It would be nice to figure out some form of improvements to formatting error chains. Any such improvements cannot be a breaking change. We do not have any specific proposals on the table at this time. Errors have a user-facing component (the string returned by the To address the specific questions (although I'm not the review meeting, and have no official status here):
|
Breaking changes are clearly the biggest concern. I'll expand on those. I'll use a basic example: say there is an error chain of 4 errors, with Which brings me to my point about the breaking change: whatever new functionality is added to errors to support fomatting, it is not optional for wrapping errors. All errors implementing the new go1.13 So my question is: Luckily, the interface was not named so hopefully it's adoption is limited, and those using it via golang.org/x/xerrors are using an experimental package and as such should tolerate breaking changes. But it still highlights my point that if we are to change it at all, better sooner than later. |
I should list, for completeness, that the other option is to rely (and make part of the contract) that |
We can't make a change to |
There is no proposal here so I'm going to drop this out of the proposal process for now. Please feel free to continue discussing. |
Concrete proposal put forward in #36994 |
I released a library with the discussed features: https://github.com/JavierZunzunegui/zerrors. |
This is a follow up to the adopted proposal #29934, the go1.13 errors. It is not a proposal, but an attempt to raise awareness of some issues with it.
I am concerned about two omissions:
err1 + ": " + err2
may be the default, but should not be the only way to do it. It was a significant part of the initial proposal (Error Values — Problem Overview, Error Printing — Draft Design), but was silently dropped as a requirement after flaws were identified in the implementation put forward.err1 + ": " + err2 + ": " + err3 + ": err4
, all intermediate strings (err4
,err3 + ": " + err4
,err2 + ": " + err3 + ": " + err4
) are also allocated (benchmark, may be a bit outdated, ignore the alternative presented there). While, to my knowledge, this is common to the other popular error libraries before go1.13, it seems natural to consider improving on it, particularly given the longer error chains expected as this becomes more popular and potentially stack frames are added.My ultimate concern is that the go1.13 errors changes, particularly
interface {Unwrap() error}
can't be made to tackle the above without requiring all such errors to implement additional, non-optional functionality, a breaking change of difficult enforcement. The longer the community is left without guidance of this, and the more custom errors are added with theUnwrap
method, the bigger the required breaking change becomes and consequently the less likely it is that go errors may ever have such functionality.My questions to the Go 2 review meeting are:
Full disclosure, I have raised this concerns before in the official proposal issue and my own counter-proposal (and am grateful for the time go team members did spend on them), but I failed to highlight these concerns with sufficient clarity.
I am also addressing the Go 2 review meeting specifically, since I believe the above are not of concern to some memeber of the go team, but I'd like to know if that is the consensus.
And, in passing, thanks to the go team for introducing the Go 2 review meeting ❤️ - it provides much appreciated visibility and accountability!
The text was updated successfully, but these errors were encountered: