@@ -2,24 +2,23 @@ package swarm
22
33import (
44 "context"
5+ "errors"
56 "fmt"
67 "sort"
7- "strings"
88
99 "github.com/docker/cli/cli/command"
1010 "github.com/docker/cli/cli/command/stack/options"
1111 "github.com/docker/docker/api/types/network"
1212 "github.com/docker/docker/api/types/swarm"
1313 "github.com/docker/docker/api/types/versions"
1414 "github.com/docker/docker/client"
15- "github.com/pkg/errors"
1615)
1716
1817// RunRemove is the swarm implementation of docker stack remove
1918func RunRemove (ctx context.Context , dockerCli command.Cli , opts options.Remove ) error {
2019 apiClient := dockerCli .Client ()
2120
22- var errs []string
21+ var errs []error
2322 for _ , namespace := range opts .Namespaces {
2423 services , err := getStackServices (ctx , apiClient , namespace )
2524 if err != nil {
@@ -52,28 +51,25 @@ func RunRemove(ctx context.Context, dockerCli command.Cli, opts options.Remove)
5251 continue
5352 }
5453
54+ // TODO(thaJeztah): change this "hasError" boolean to return a (multi-)error for each of these functions instead.
5555 hasError := removeServices (ctx , dockerCli , services )
5656 hasError = removeSecrets (ctx , dockerCli , secrets ) || hasError
5757 hasError = removeConfigs (ctx , dockerCli , configs ) || hasError
5858 hasError = removeNetworks (ctx , dockerCli , networks ) || hasError
5959
6060 if hasError {
61- errs = append (errs , "Failed to remove some resources from stack: "+ namespace )
61+ errs = append (errs , errors . New ( "failed to remove some resources from stack: "+ namespace ) )
6262 continue
6363 }
6464
6565 if ! opts .Detach {
6666 err = waitOnTasks (ctx , apiClient , namespace )
6767 if err != nil {
68- errs = append (errs , fmt .Sprintf ( "Failed to wait on tasks of stack: %s: %s " , namespace , err ))
68+ errs = append (errs , fmt .Errorf ( "failed to wait on tasks of stack: %s: %w " , namespace , err ))
6969 }
7070 }
7171 }
72-
73- if len (errs ) > 0 {
74- return errors .New (strings .Join (errs , "\n " ))
75- }
76- return nil
72+ return errors .Join (errs ... )
7773}
7874
7975func sortServiceByName (services []swarm.Service ) func (i , j int ) bool {
0 commit comments