Skip to content

Commit 1aab64d

Browse files
authored
Merge pull request #5547 from thaJeztah/plugin_better_error
cli/command/plugins: use errors.Join instead of custom cli.Errors, and deprecate cli.Errors
2 parents 0ab0eca + d3bafa5 commit 1aab64d

2 files changed

Lines changed: 7 additions & 8 deletions

File tree

cli/command/plugin/remove.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package plugin
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67

78
"github.com/docker/cli/cli"
@@ -36,17 +37,13 @@ func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
3637
}
3738

3839
func runRemove(ctx context.Context, dockerCli command.Cli, opts *rmOptions) error {
39-
var errs cli.Errors
40+
var errs error
4041
for _, name := range opts.plugins {
4142
if err := dockerCli.Client().PluginRemove(ctx, name, types.PluginRemoveOptions{Force: opts.force}); err != nil {
42-
errs = append(errs, err)
43+
errs = errors.Join(errs, err)
4344
continue
4445
}
45-
fmt.Fprintln(dockerCli.Out(), name)
46+
_, _ = fmt.Fprintln(dockerCli.Out(), name)
4647
}
47-
// Do not simplify to `return errs` because even if errs == nil, it is not a nil-error interface value.
48-
if errs != nil {
49-
return errs
50-
}
51-
return nil
48+
return errs
5249
}

cli/error.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
// Errors is a list of errors.
99
// Useful in a loop if you don't want to return the error right away and you want to display after the loop,
1010
// all the errors that happened during the loop.
11+
//
12+
// Deprecated: use [errors.Join] instead; will be removed in the next release.
1113
type Errors []error
1214

1315
func (errList Errors) Error() string {

0 commit comments

Comments
 (0)