Skip to content

Commit 44dfe20

Browse files
committed
cli/command/stack: use stdlib errors
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent d967ed8 commit 44dfe20

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

cli/command/stack/deploy.go

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

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

78
"github.com/docker/cli/cli"
@@ -10,7 +11,6 @@ import (
1011
composetypes "github.com/docker/cli/cli/compose/types"
1112
"github.com/moby/moby/api/types/swarm"
1213
"github.com/moby/moby/api/types/versions"
13-
"github.com/pkg/errors"
1414
"github.com/spf13/cobra"
1515
"github.com/spf13/pflag"
1616
)
@@ -80,7 +80,7 @@ func runDeploy(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet,
8080
case resolveImageAlways, resolveImageChanged, resolveImageNever:
8181
// valid options.
8282
default:
83-
return errors.Errorf("Invalid option %s for flag --resolve-image", opts.resolveImage)
83+
return fmt.Errorf("invalid option %s for flag --resolve-image", opts.resolveImage)
8484
}
8585

8686
// client side image resolution should not be done when the supported
@@ -108,7 +108,7 @@ func checkDaemonIsSwarmManager(ctx context.Context, dockerCli command.Cli) error
108108
return err
109109
}
110110
if !info.Swarm.ControlAvailable {
111-
return errors.New("this node is not a swarm manager. Use \"docker swarm init\" or \"docker swarm join\" to connect this node to swarm and try again")
111+
return errors.New(`this node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again`)
112112
}
113113
return nil
114114
}

cli/command/stack/list_utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package stack
22

33
import (
44
"context"
5+
"errors"
56

67
"github.com/docker/cli/cli/compose/convert"
78
"github.com/moby/moby/client"
8-
"github.com/pkg/errors"
99
)
1010

1111
// getStacks lists the swarm stacks with the number of services they contain.

cli/command/stack/loader.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package stack
55

66
import (
7+
"errors"
78
"fmt"
89
"io"
910
"os"
@@ -17,7 +18,6 @@ import (
1718
"github.com/docker/cli/cli/compose/loader"
1819
"github.com/docker/cli/cli/compose/schema"
1920
composetypes "github.com/docker/cli/cli/compose/types"
20-
"github.com/pkg/errors"
2121
)
2222

2323
// loadComposeFile parse the composefile specified in the cli and returns its configOptions and version.
@@ -30,9 +30,10 @@ func loadComposeFile(streams command.Streams, opts deployOptions) (*composetypes
3030
dicts := getDictsFrom(configDetails.ConfigFiles)
3131
config, err := loader.Load(configDetails)
3232
if err != nil {
33-
if fpe, ok := err.(*loader.ForbiddenPropertiesError); ok {
33+
var fpe *loader.ForbiddenPropertiesError
34+
if errors.As(err, &fpe) {
3435
// this error is intentionally formatted multi-line
35-
return nil, errors.Errorf("Compose file contains unsupported options:\n\n%s\n", propertyWarnings(fpe.Properties))
36+
return nil, fmt.Errorf("compose file contains unsupported options:\n\n%s\n", propertyWarnings(fpe.Properties)) //nolint:staticcheck // ignore ST1005
3637
}
3738

3839
return nil, err
@@ -53,10 +54,10 @@ func loadComposeFile(streams command.Streams, opts deployOptions) (*composetypes
5354
// Validate if each service has a valid image-reference.
5455
for _, svc := range config.Services {
5556
if svc.Image == "" {
56-
return nil, errors.Errorf("invalid image reference for service %s: no image specified", svc.Name)
57+
return nil, fmt.Errorf("invalid image reference for service %s: no image specified", svc.Name)
5758
}
5859
if _, err := reference.ParseAnyReference(svc.Image); err != nil {
59-
return nil, errors.Wrapf(err, "invalid image reference for service %s", svc.Name)
60+
return nil, fmt.Errorf("invalid image reference for service %s: %w", svc.Name, err)
6061
}
6162
}
6263

@@ -87,7 +88,7 @@ func getConfigDetails(composefiles []string, stdin io.Reader) (composetypes.Conf
8788
var details composetypes.ConfigDetails
8889

8990
if len(composefiles) == 0 {
90-
return details, errors.New("Specify a Compose file (with --compose-file)")
91+
return details, errors.New("specify a Compose file (with --compose-file)")
9192
}
9293

9394
if composefiles[0] == "-" && len(composefiles) == 1 {
@@ -133,7 +134,7 @@ func buildEnvironment(env []string) (map[string]string, error) {
133134

134135
k, v, ok := strings.Cut(s, "=")
135136
if !ok || k == "" {
136-
return result, errors.Errorf("unexpected environment variable '%s'", s)
137+
return result, fmt.Errorf("unexpected environment variable '%s'", s)
137138
}
138139
// value may be set, but empty if "s" is like "K=", not "K".
139140
result[k] = v

0 commit comments

Comments
 (0)