Skip to content

Commit 935df8a

Browse files
committed
cli/command/node: runPs: use native errors.Join
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 183337d commit 935df8a

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

cli/command/node/ps.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package node
22

33
import (
44
"context"
5-
"strings"
5+
"errors"
66

77
"github.com/docker/cli/cli"
88
"github.com/docker/cli/cli/command"
@@ -11,7 +11,6 @@ import (
1111
"github.com/docker/cli/opts"
1212
"github.com/moby/moby/api/types/swarm"
1313
"github.com/moby/moby/client"
14-
"github.com/pkg/errors"
1514
"github.com/spf13/cobra"
1615
"github.com/spf13/pflag"
1716
)
@@ -64,20 +63,20 @@ func runPs(ctx context.Context, dockerCLI command.Cli, options psOptions) error
6463
apiClient := dockerCLI.Client()
6564

6665
var (
67-
errs []string
66+
errs []error
6867
tasks []swarm.Task
6968
)
7069

7170
for _, nodeID := range options.nodeIDs {
7271
nodeRef, err := Reference(ctx, apiClient, nodeID)
7372
if err != nil {
74-
errs = append(errs, err.Error())
73+
errs = append(errs, err)
7574
continue
7675
}
7776

7877
node, _, err := apiClient.NodeInspectWithRaw(ctx, nodeRef)
7978
if err != nil {
80-
errs = append(errs, err.Error())
79+
errs = append(errs, err)
8180
continue
8281
}
8382

@@ -86,7 +85,7 @@ func runPs(ctx context.Context, dockerCLI command.Cli, options psOptions) error
8685

8786
nodeTasks, err := apiClient.TaskList(ctx, client.TaskListOptions{Filters: filter})
8887
if err != nil {
89-
errs = append(errs, err.Error())
88+
errs = append(errs, err)
9089
continue
9190
}
9291

@@ -100,13 +99,9 @@ func runPs(ctx context.Context, dockerCLI command.Cli, options psOptions) error
10099

101100
if len(errs) == 0 || len(tasks) != 0 {
102101
if err := task.Print(ctx, dockerCLI, tasks, idresolver.New(apiClient, options.noResolve), !options.noTrunc, options.quiet, format); err != nil {
103-
errs = append(errs, err.Error())
102+
errs = append(errs, err)
104103
}
105104
}
106105

107-
if len(errs) > 0 {
108-
return errors.Errorf("%s", strings.Join(errs, "\n"))
109-
}
110-
111-
return nil
106+
return errors.Join(errs...)
112107
}

0 commit comments

Comments
 (0)