From 935df8a78fe2a6cf628d34ff21473f847ef18596 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 8 Sep 2025 19:28:38 +0200 Subject: [PATCH 1/2] cli/command/node: runPs: use native errors.Join Signed-off-by: Sebastiaan van Stijn --- cli/command/node/ps.go | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/cli/command/node/ps.go b/cli/command/node/ps.go index 8dd6949657..cfb38ae12c 100644 --- a/cli/command/node/ps.go +++ b/cli/command/node/ps.go @@ -2,7 +2,7 @@ package node import ( "context" - "strings" + "errors" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" @@ -11,7 +11,6 @@ import ( "github.com/docker/cli/opts" "github.com/moby/moby/api/types/swarm" "github.com/moby/moby/client" - "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -64,20 +63,20 @@ func runPs(ctx context.Context, dockerCLI command.Cli, options psOptions) error apiClient := dockerCLI.Client() var ( - errs []string + errs []error tasks []swarm.Task ) for _, nodeID := range options.nodeIDs { nodeRef, err := Reference(ctx, apiClient, nodeID) if err != nil { - errs = append(errs, err.Error()) + errs = append(errs, err) continue } node, _, err := apiClient.NodeInspectWithRaw(ctx, nodeRef) if err != nil { - errs = append(errs, err.Error()) + errs = append(errs, err) continue } @@ -86,7 +85,7 @@ func runPs(ctx context.Context, dockerCLI command.Cli, options psOptions) error nodeTasks, err := apiClient.TaskList(ctx, client.TaskListOptions{Filters: filter}) if err != nil { - errs = append(errs, err.Error()) + errs = append(errs, err) continue } @@ -100,13 +99,9 @@ func runPs(ctx context.Context, dockerCLI command.Cli, options psOptions) error if len(errs) == 0 || len(tasks) != 0 { if err := task.Print(ctx, dockerCLI, tasks, idresolver.New(apiClient, options.noResolve), !options.noTrunc, options.quiet, format); err != nil { - errs = append(errs, err.Error()) + errs = append(errs, err) } } - if len(errs) > 0 { - return errors.Errorf("%s", strings.Join(errs, "\n")) - } - - return nil + return errors.Join(errs...) } From 5df02441ca870f8c2d40ff3dd1cfa1d2cc14470f Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 8 Sep 2025 19:53:43 +0200 Subject: [PATCH 2/2] cli/command/containers: runUpdate: use native errors.Join Signed-off-by: Sebastiaan van Stijn --- cli/command/container/update.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/cli/command/container/update.go b/cli/command/container/update.go index 4c2a7719c3..98344bab75 100644 --- a/cli/command/container/update.go +++ b/cli/command/container/update.go @@ -2,6 +2,7 @@ package container import ( "context" + "errors" "fmt" "strings" @@ -10,7 +11,6 @@ import ( "github.com/docker/cli/cli/command/completion" "github.com/docker/cli/opts" containertypes "github.com/moby/moby/api/types/container" - "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -131,12 +131,12 @@ func runUpdate(ctx context.Context, dockerCli command.Cli, options *updateOption var ( warns []string - errs []string + errs []error ) for _, ctr := range options.containers { r, err := dockerCli.Client().ContainerUpdate(ctx, ctr, updateConfig) if err != nil { - errs = append(errs, err.Error()) + errs = append(errs, err) } else { _, _ = fmt.Fprintln(dockerCli.Out(), ctr) } @@ -145,8 +145,5 @@ func runUpdate(ctx context.Context, dockerCli command.Cli, options *updateOption if len(warns) > 0 { _, _ = fmt.Fprintln(dockerCli.Out(), strings.Join(warns, "\n")) } - if len(errs) > 0 { - return errors.New(strings.Join(errs, "\n")) - } - return nil + return errors.Join(errs...) }