From 2a9fd4a939470c16eeec2f40b258956cf004fb0a Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 3 Feb 2025 19:30:56 +0100 Subject: [PATCH] cli/command/node: use errors.Join Use stdlib multi-errors instead of creating our own Signed-off-by: Sebastiaan van Stijn --- cli/command/node/remove.go | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/cli/command/node/remove.go b/cli/command/node/remove.go index 809c6b16fa..8e9460c95a 100644 --- a/cli/command/node/remove.go +++ b/cli/command/node/remove.go @@ -2,13 +2,12 @@ package node import ( "context" + "errors" "fmt" - "strings" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/docker/api/types" - "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -36,20 +35,13 @@ func newRemoveCommand(dockerCli command.Cli) *cobra.Command { func runRemove(ctx context.Context, dockerCLI command.Cli, nodeIDs []string, opts removeOptions) error { apiClient := dockerCLI.Client() - var errs []string - + var errs []error for _, id := range nodeIDs { - err := apiClient.NodeRemove(ctx, id, types.NodeRemoveOptions{Force: opts.force}) - if err != nil { - errs = append(errs, err.Error()) + if err := apiClient.NodeRemove(ctx, id, types.NodeRemoveOptions{Force: opts.force}); err != nil { + errs = append(errs, err) continue } _, _ = fmt.Fprintln(dockerCLI.Out(), id) } - - if len(errs) > 0 { - return errors.Errorf("%s", strings.Join(errs, "\n")) - } - - return nil + return errors.Join(errs...) }