-
Notifications
You must be signed in to change notification settings - Fork 43
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
Enable Errors support for any multi-error #75
Conversation
Starting Go 1.20, any multi-error should conform to the standard unwrap method: Unwrap() []error. This changes multierr.Errors() method to support any error that complies to that interface. Fix #70.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Please add a changelog entry.
return []error{err} | ||
} | ||
|
||
return append(([]error)(nil), eg.Unwrap()...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of curiosity, why a new slice rather than the old one?
it would seem that any unrwappable error should be okay with us passing the slice up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a new slice because multierr.Errors specifically returns a copy of the slice.
Docs say:
Callers of this function are free to modify the returned slice.
Unwrap() []error
returns the underlying slice. Per the proposal:
Callers must not modify the list returned by Unwrap.
And indeed, in the implementation:
func (e *joinError) Unwrap() []error {
return e.errs
}
So we have to create a new slice here.
Codecov Report
@@ Coverage Diff @@
## master #75 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 3 3
Lines 110 117 +7
=========================================
+ Hits 110 117 +7
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Starting Go 1.20, any multi-error should conform to the standard unwrap method: Unwrap() []error.
This changes multierr.Errors() method to support any error that complies to that interface.
Fix #70 / GO-1883