Skip to content

Commit

Permalink
Merge pull request #5547 from thaJeztah/plugin_better_error
Browse files Browse the repository at this point in the history
cli/command/plugins: use errors.Join instead of custom cli.Errors, and deprecate cli.Errors
  • Loading branch information
thaJeztah authored Oct 22, 2024
2 parents 0ab0eca + d3bafa5 commit 1aab64d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 5 additions & 8 deletions cli/command/plugin/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package plugin

import (
"context"
"errors"
"fmt"

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

func runRemove(ctx context.Context, dockerCli command.Cli, opts *rmOptions) error {
var errs cli.Errors
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)
continue
}
fmt.Fprintln(dockerCli.Out(), name)
_, _ = fmt.Fprintln(dockerCli.Out(), name)
}
// Do not simplify to `return errs` because even if errs == nil, it is not a nil-error interface value.
if errs != nil {
return errs
}
return nil
return errs
}
2 changes: 2 additions & 0 deletions cli/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
// Errors is a list of errors.
// Useful in a loop if you don't want to return the error right away and you want to display after the loop,
// all the errors that happened during the loop.
//
// Deprecated: use [errors.Join] instead; will be removed in the next release.
type Errors []error

func (errList Errors) Error() string {
Expand Down

0 comments on commit 1aab64d

Please sign in to comment.