-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: add example around unwrapping errors.Join #69586
Comments
see #57358 |
@seankhliao I'm not proposing a new way of interacting with these errors, but adding an example with errors.As and joined errors so that it's easier for people to get the individual items. Would you object to that? |
I think the example would be OK if you want to send it. No issue is required. See https://go.dev/doc/contribute. Thanks. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Go version
go version go1.21.6 linux/amd64
Output of
go env
in your module/workspace:What did you do?
I used errors.Join to group a bunch of errors together, but then realized that getting the individual entries back is not straightforward (unless I'm missing something); the ways I could spot to get the errors back would be to use errors.As or an inline cast to
Unwrap() []error
.Should we include an example that shows people to handle this task to set some best practices/precedence?
https://go.dev/play/p/G5vw-xdqBvm
What did you see happen?
The
errors
package documentation states:It also states that
and that
I think that the two following statements are contradictory since calling
errors.Unwrap(errors.Join(err1, err2))
will return nil, even though we said that Join returns a wrapped error. The first statement is only true for a kind of wrapped errors.What did you expect to see?
An documented way to get the individual errors back instead of fiddling to find the right interface to cast to.
The text was updated successfully, but these errors were encountered: