Merge pull request #5547 from thaJeztah/plugin_better_error

cli/command/plugins: use errors.Join instead of custom cli.Errors, and deprecate cli.Errors
This commit is contained in:
Sebastiaan van Stijn 2024-10-22 10:42:26 +02:00 committed by GitHub
commit 1aab64dd90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package plugin
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"github.com/docker/cli/cli" "github.com/docker/cli/cli"
@ -36,17 +37,13 @@ func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
} }
func runRemove(ctx context.Context, dockerCli command.Cli, opts *rmOptions) error { func runRemove(ctx context.Context, dockerCli command.Cli, opts *rmOptions) error {
var errs cli.Errors var errs error
for _, name := range opts.plugins { for _, name := range opts.plugins {
if err := dockerCli.Client().PluginRemove(ctx, name, types.PluginRemoveOptions{Force: opts.force}); err != nil { if err := dockerCli.Client().PluginRemove(ctx, name, types.PluginRemoveOptions{Force: opts.force}); err != nil {
errs = append(errs, err) errs = errors.Join(errs, err)
continue 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 errs
} }
return nil
}

View File

@ -8,6 +8,8 @@ import (
// Errors is a list of errors. // 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, // 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. // all the errors that happened during the loop.
//
// Deprecated: use [errors.Join] instead; will be removed in the next release.
type Errors []error type Errors []error
func (errList Errors) Error() string { func (errList Errors) Error() string {