cli/command/stack: use stdlib errors
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@ -15,7 +15,7 @@ func TestConfigWithEmptyComposeFile(t *testing.T) {
|
||||
cmd.SetOut(io.Discard)
|
||||
cmd.SetErr(io.Discard)
|
||||
|
||||
assert.ErrorContains(t, cmd.Execute(), `Specify a Compose file`)
|
||||
assert.ErrorContains(t, cmd.Execute(), `specify a Compose file`)
|
||||
}
|
||||
|
||||
func TestConfigMergeInterpolation(t *testing.T) {
|
||||
|
||||
@ -2,6 +2,7 @@ package stack
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/cli/cli"
|
||||
@ -10,7 +11,6 @@ import (
|
||||
composetypes "github.com/docker/cli/cli/compose/types"
|
||||
"github.com/moby/moby/api/types/swarm"
|
||||
"github.com/moby/moby/api/types/versions"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
@ -80,7 +80,7 @@ func runDeploy(ctx context.Context, dockerCLI command.Cli, flags *pflag.FlagSet,
|
||||
case resolveImageAlways, resolveImageChanged, resolveImageNever:
|
||||
// valid options.
|
||||
default:
|
||||
return errors.Errorf("Invalid option %s for flag --resolve-image", opts.resolveImage)
|
||||
return fmt.Errorf("invalid option %s for flag --resolve-image", opts.resolveImage)
|
||||
}
|
||||
|
||||
// client side image resolution should not be done when the supported
|
||||
@ -108,7 +108,7 @@ func checkDaemonIsSwarmManager(ctx context.Context, dockerCli command.Cli) error
|
||||
return err
|
||||
}
|
||||
if !info.Swarm.ControlAvailable {
|
||||
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")
|
||||
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`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -2,10 +2,10 @@ package stack
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/docker/cli/cli/compose/convert"
|
||||
"github.com/moby/moby/client"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// getStacks lists the swarm stacks with the number of services they contain.
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
package stack
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@ -17,7 +18,6 @@ import (
|
||||
"github.com/docker/cli/cli/compose/loader"
|
||||
"github.com/docker/cli/cli/compose/schema"
|
||||
composetypes "github.com/docker/cli/cli/compose/types"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// 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
|
||||
dicts := getDictsFrom(configDetails.ConfigFiles)
|
||||
config, err := loader.Load(configDetails)
|
||||
if err != nil {
|
||||
if fpe, ok := err.(*loader.ForbiddenPropertiesError); ok {
|
||||
var fpe *loader.ForbiddenPropertiesError
|
||||
if errors.As(err, &fpe) {
|
||||
// this error is intentionally formatted multi-line
|
||||
return nil, errors.Errorf("Compose file contains unsupported options:\n\n%s\n", propertyWarnings(fpe.Properties))
|
||||
return nil, fmt.Errorf("compose file contains unsupported options:\n\n%s\n", propertyWarnings(fpe.Properties)) //nolint:staticcheck // ignore ST1005
|
||||
}
|
||||
|
||||
return nil, err
|
||||
@ -53,10 +54,10 @@ func loadComposeFile(streams command.Streams, opts deployOptions) (*composetypes
|
||||
// Validate if each service has a valid image-reference.
|
||||
for _, svc := range config.Services {
|
||||
if svc.Image == "" {
|
||||
return nil, errors.Errorf("invalid image reference for service %s: no image specified", svc.Name)
|
||||
return nil, fmt.Errorf("invalid image reference for service %s: no image specified", svc.Name)
|
||||
}
|
||||
if _, err := reference.ParseAnyReference(svc.Image); err != nil {
|
||||
return nil, errors.Wrapf(err, "invalid image reference for service %s", svc.Name)
|
||||
return nil, fmt.Errorf("invalid image reference for service %s: %w", svc.Name, err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,7 +88,7 @@ func getConfigDetails(composefiles []string, stdin io.Reader) (composetypes.Conf
|
||||
var details composetypes.ConfigDetails
|
||||
|
||||
if len(composefiles) == 0 {
|
||||
return details, errors.New("Specify a Compose file (with --compose-file)")
|
||||
return details, errors.New("specify a Compose file (with --compose-file)")
|
||||
}
|
||||
|
||||
if composefiles[0] == "-" && len(composefiles) == 1 {
|
||||
@ -133,7 +134,7 @@ func buildEnvironment(env []string) (map[string]string, error) {
|
||||
|
||||
k, v, ok := strings.Cut(s, "=")
|
||||
if !ok || k == "" {
|
||||
return result, errors.Errorf("unexpected environment variable '%s'", s)
|
||||
return result, fmt.Errorf("unexpected environment variable '%s'", s)
|
||||
}
|
||||
// value may be set, but empty if "s" is like "K=", not "K".
|
||||
result[k] = v
|
||||
|
||||
Reference in New Issue
Block a user