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.
abhinav
left a comment
There was a problem hiding this comment.
LGTM!
Please add a changelog entry.
| return []error{err} | ||
| } | ||
|
|
||
| return append(([]error)(nil), eg.Unwrap()...) |
There was a problem hiding this comment.
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.
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