Remove hashicorp/go-multierror dependency#8992
Conversation
|
Skipping CI for Draft Pull Request. |
1597909 to
2ab1bd7
Compare
|
/test all |
|
/retest |
1 similar comment
|
/retest |
| status, sErr := dmsetup.Status(s.pool.poolName) | ||
| if sErr != nil { | ||
| multierror.Append(err, sErr) | ||
| errs = append(errs, sErr) |
There was a problem hiding this comment.
The previous code actually has a bug. If err is a error type, multierror.Append(err, sErr) will create a new multierror.Error type and append sErr there. It should be err = multierror.Append(err, sErr).
2ab1bd7 to
4da1749
Compare
Signed-off-by: Jin Dong <jin.dong@databricks.com>
4da1749 to
cd8c8ae
Compare
| result = append(result, fn()) | ||
| } | ||
| err = multierror.Flatten(result) | ||
| err = errors.Join(result...) |
There was a problem hiding this comment.
multierror.Flatten is only called here, so not sure if it's necessary. If so, maybe we can write a simple helper to do that.
|
/test all |
snapshots/devmapper/pool_device.go
Outdated
| return e.Errors[0] | ||
| if joinErr, ok := e.(interface{ Unwrap() []error }); ok { | ||
| if errs := joinErr.Unwrap(); len(errs) == 1 { | ||
| return errs[0] |
There was a problem hiding this comment.
If I recall this right, we required this unwrapping helper for error comparisons to work. Which can now be replaced with error.Is. I wonder if we can now remove this?
There was a problem hiding this comment.
thanks for the context. I remember there're 2 places where the unwrap is used. Let me take a look at both.
There was a problem hiding this comment.
Digging into a little bit, unwrapError was introduced in #4437. At that time it seems multierror 1.0.0 is used (or at least older than 1.1.0).
My guess is unwrapError was required to expose the underlying unix.ENODATA error within multierror which was handled below
containerd/snapshots/devmapper/pool_device.go
Line 545 in fb786b2
It was needed because at that time, errors.Is seems not work with multierror:
In this playground with multierror 1.0.0, errors.Is returns false: https://go.dev/play/p/29rAHWAV310
In this playground with multierror 1.1.0, errors.Is returns true: https://go.dev/play/p/UpFMxRkmjcc
And now since errors.Is works with both multierror 1.1.0 and errors.Join, we can safely remove this regardless :)
Signed-off-by: Jin Dong <jin.dong@databricks.com>
| // Unwrap if just one error | ||
| if len(result.Errors) == 1 { | ||
| return result.Errors[0] | ||
| } |
There was a problem hiding this comment.
I also removed this Unwrap since most cases don't have such Unwrap logic unless specifically needed.
Only such case I found is the code below (to handle cleanupErr separately).
containerd/pkg/cri/sbserver/sandbox_run.go
Lines 256 to 266 in fb786b2
|
/cherry-pick release/1.7 |
|
@djdongjin: #8992 failed to apply on top of branch "release/1.7": DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Remove
github.com/hashicorp/go-multierrorand replace witherrors.Joinin std.Some concept equivalents:
var errs multierror.Error=var errs []errorerrs = multierror.Append(errs, err)=errs = append(errs, err)multierror.ErrorOrNil(errs)=errors.Join(errs)errs.WrappedErrors()=err.(interface{ Unwrap() []error }).Unwrap()One behavior difference between
multierror.Appendanderrors.Joinis that the former will append to an existing multierror if it is (so the new one has a length of N + 1), while the latter will create a newjoinErrorwhich includes previous error and the new one (so the new one has a length of 2)https://go.dev/play/p/ryeimUucDyb
I think the recommended use pattern of
errors.Joinis to have aerrs [] errorto save all the errors along the way and aerrors.Join(errs...)at the end to produce onejoinError.https://pkg.go.dev/errors#Join
golang/go#60209
golang/go#53435 (comment)