Skip to content

Commit 7147e85

Browse files
committed
cli/command/image: use errors.Join
Use stdlib multi-errors instead of creating our own Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent 2b9a4d5 commit 7147e85

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

cli/command/image/remove.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ package image
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
6-
"strings"
77

88
"github.com/docker/cli/cli"
99
"github.com/docker/cli/cli/command"
1010
"github.com/docker/cli/cli/command/completion"
1111
"github.com/docker/docker/api/types/image"
1212
"github.com/docker/docker/errdefs"
13-
"github.com/pkg/errors"
1413
"github.com/spf13/cobra"
1514
)
1615

@@ -59,15 +58,16 @@ func runRemove(ctx context.Context, dockerCLI command.Cli, opts removeOptions, i
5958
PruneChildren: !opts.noPrune,
6059
}
6160

62-
var errs []string
61+
// TODO(thaJeztah): this logic can likely be simplified: do we want to print "not found" errors at all when using "force"?
6362
fatalErr := false
63+
var errs []error
6464
for _, img := range images {
6565
dels, err := apiClient.ImageRemove(ctx, img, options)
6666
if err != nil {
6767
if !errdefs.IsNotFound(err) {
6868
fatalErr = true
6969
}
70-
errs = append(errs, err.Error())
70+
errs = append(errs, err)
7171
} else {
7272
for _, del := range dels {
7373
if del.Deleted != "" {
@@ -79,12 +79,11 @@ func runRemove(ctx context.Context, dockerCLI command.Cli, opts removeOptions, i
7979
}
8080
}
8181

82-
if len(errs) > 0 {
83-
msg := strings.Join(errs, "\n")
82+
if err := errors.Join(errs...); err != nil {
8483
if !opts.force || fatalErr {
85-
return errors.New(msg)
84+
return err
8685
}
87-
_, _ = fmt.Fprintln(dockerCLI.Err(), msg)
86+
_, _ = fmt.Fprintln(dockerCLI.Err(), err)
8887
}
8988
return nil
9089
}

0 commit comments

Comments
 (0)