-
Notifications
You must be signed in to change notification settings - Fork 2.1k
cli/command/plugins: use errors.Join instead of custom cli.Errors, and deprecate cli.Errors #5547
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
Conversation
This command was using a custom "multi-error" implementation, but it
had some limitations, and the formatting wasn't great.
This patch replaces it with Go's errors.Join.
Before:
docker plugin remove one two three
Error response from daemon: plugin "one" not found, Error response from daemon: plugin "two" not found, Error response from daemon: plugin "three" not found
After:
docker plugin remove one two three
Error response from daemon: plugin "one" not found
Error response from daemon: plugin "two" not found
Error response from daemon: plugin "three" not found
Signed-off-by: Sebastiaan van Stijn <[email protected]>
The Errors type is no longer used by the CLI itself, and this custom "multi-error" implementation had both limitations (empty list not being `nil`), as well as formatting not being great. All of this making it not something to recommend, and better handled with Go's stdlib. As far as I could find, there's no external consumers of this, but let's deprecate first, and remove in the next release. Signed-off-by: Sebastiaan van Stijn <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5547 +/- ##
==========================================
- Coverage 59.57% 59.57% -0.01%
==========================================
Files 345 345
Lines 29088 29085 -3
==========================================
- Hits 17330 17327 -3
Misses 10788 10788
Partials 970 970 |
| var errs error | ||
| for _, name := range opts.plugins { | ||
| if err := dockerCli.Client().PluginRemove(ctx, name, types.PluginRemoveOptions{Force: opts.force}); err != nil { | ||
| errs = append(errs, err) | ||
| errs = errors.Join(errs, err) |
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.
This is not the same as the previous one, as it always produce *joinError with []error of length 2. The first error is of type *errors.joinError which combines all of the previous errors.
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.
The correct way to use errors.Join in this case is to first collect errors into errs []error and then return errors.Join(errs...)
cli/command/plugins: use errors.Join instead of custom cli.Errors
This command was using a custom "multi-error" implementation, but it
had some limitations, and the formatting wasn't great.
This patch replaces it with Go's errors.Join.
Before:
After:
cli: deprecate Errors type
The Errors type is no longer used by the CLI itself, and this custom
"multi-error" implementation had both limitations (empty list not being
nil), as well as formatting not being great. All of this making it notsomething to recommend, and better handled with Go's stdlib.
As far as I could find, there's no external consumers of this, but let's
deprecate first, and remove in the next release.
- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)