Skip to content

Commit 62d2520

Browse files
authored
Merge pull request #6440 from thaJeztah/use_multierror
use native errors.Join for multi-errors on "docker ps", "docker node ls"
2 parents 183337d + 5df0244 commit 62d2520

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

cli/command/container/update.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package container
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"strings"
78

@@ -10,7 +11,6 @@ import (
1011
"github.com/docker/cli/cli/command/completion"
1112
"github.com/docker/cli/opts"
1213
containertypes "github.com/moby/moby/api/types/container"
13-
"github.com/pkg/errors"
1414
"github.com/spf13/cobra"
1515
)
1616

@@ -131,12 +131,12 @@ func runUpdate(ctx context.Context, dockerCli command.Cli, options *updateOption
131131

132132
var (
133133
warns []string
134-
errs []string
134+
errs []error
135135
)
136136
for _, ctr := range options.containers {
137137
r, err := dockerCli.Client().ContainerUpdate(ctx, ctr, updateConfig)
138138
if err != nil {
139-
errs = append(errs, err.Error())
139+
errs = append(errs, err)
140140
} else {
141141
_, _ = fmt.Fprintln(dockerCli.Out(), ctr)
142142
}
@@ -145,8 +145,5 @@ func runUpdate(ctx context.Context, dockerCli command.Cli, options *updateOption
145145
if len(warns) > 0 {
146146
_, _ = fmt.Fprintln(dockerCli.Out(), strings.Join(warns, "\n"))
147147
}
148-
if len(errs) > 0 {
149-
return errors.New(strings.Join(errs, "\n"))
150-
}
151-
return nil
148+
return errors.Join(errs...)
152149
}

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)