From fa30284bd419dab0a3d12fe5828455fa3df076e1 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Wed, 9 Oct 2024 17:10:45 -0700 Subject: [PATCH] Switch from pkg/errors to %w part 2 The github.com/pkg/errors is mostly obsoleted since Go 1.13 introduced %w-style error wrapping. It is also not maintained and is now archived by the owner. Let's switch to %s-style error wrapping. Generated by git ls-files *.go | grep -v '^vendor/' | xargs go-wrap-to-percent-w -w using https://github.com/AkihiroSuda/go-wrap-to-percent-w tool. Signed-off-by: Kir Kolyshkin --- cli-plugins/manager/error.go | 6 +- cli-plugins/manager/plugin.go | 9 +-- cli-plugins/manager/suffix_windows.go | 7 +-- cli/cobra.go | 4 +- cli/command/checkpoint/create_test.go | 5 +- cli/command/checkpoint/list_test.go | 5 +- cli/command/checkpoint/remove_test.go | 5 +- cli/command/cli.go | 9 +-- cli/command/cli_options.go | 8 +-- cli/command/cli_test.go | 3 +- cli/command/config/create.go | 4 +- cli/command/config/create_test.go | 13 ++-- cli/command/config/inspect_test.go | 8 +-- cli/command/config/ls_test.go | 5 +- cli/command/config/remove.go | 4 +- cli/command/config/remove_test.go | 7 ++- cli/command/container/attach.go | 3 +- cli/command/container/attach_test.go | 6 +- cli/command/container/commit_test.go | 3 +- cli/command/container/cp.go | 7 ++- cli/command/container/create.go | 12 ++-- cli/command/container/diff.go | 3 +- cli/command/container/diff_test.go | 3 +- cli/command/container/exec.go | 3 +- cli/command/container/exec_test.go | 6 +- cli/command/container/export.go | 6 +- cli/command/container/kill.go | 3 +- cli/command/container/list.go | 7 ++- cli/command/container/opts.go | 63 ++++++++++--------- cli/command/container/opts_test.go | 4 +- cli/command/container/pause.go | 3 +- cli/command/container/port.go | 6 +- cli/command/container/prune.go | 3 +- cli/command/container/prune_test.go | 2 +- cli/command/container/rename.go | 5 +- cli/command/container/rename_test.go | 3 +- cli/command/container/restart.go | 3 +- cli/command/container/restart_test.go | 3 +- cli/command/container/rm.go | 3 +- cli/command/container/run.go | 3 +- cli/command/container/start.go | 5 +- cli/command/container/stats.go | 3 +- cli/command/container/stats_helpers.go | 3 +- cli/command/container/stop.go | 3 +- cli/command/container/stop_test.go | 3 +- cli/command/container/tty_test.go | 5 +- cli/command/container/unpause.go | 3 +- cli/command/container/update.go | 3 +- cli/command/container/wait.go | 3 +- cli/command/context/create.go | 9 +-- cli/command/context/options.go | 8 +-- cli/command/context/remove.go | 7 ++- cli/command/context/update.go | 4 +- cli/command/defaultcontextstore.go | 5 +- cli/command/formatter/formatter.go | 6 +- cli/command/formatter/reflect.go | 11 ++-- cli/command/idresolver/idresolver.go | 4 +- cli/command/idresolver/idresolver_test.go | 9 +-- cli/command/image/build.go | 15 ++--- cli/command/image/build/context.go | 44 ++++++------- cli/command/image/history_test.go | 4 +- cli/command/image/import_test.go | 5 +- cli/command/image/list_test.go | 4 +- cli/command/image/load.go | 5 +- cli/command/image/load_test.go | 4 +- cli/command/image/prune.go | 3 +- cli/command/image/prune_test.go | 5 +- cli/command/image/pull.go | 3 +- cli/command/image/push.go | 3 +- cli/command/image/push_test.go | 5 +- cli/command/image/remove.go | 3 +- cli/command/image/remove_test.go | 6 +- cli/command/image/save.go | 6 +- cli/command/image/save_test.go | 5 +- cli/command/image/trust.go | 19 +++--- cli/command/inspect/inspector.go | 11 ++-- cli/command/manifest/annotate.go | 8 +-- cli/command/manifest/create_list.go | 8 +-- cli/command/manifest/create_test.go | 7 ++- cli/command/manifest/inspect.go | 4 +- cli/command/manifest/inspect_test.go | 6 +- cli/command/manifest/push.go | 17 ++--- cli/command/manifest/push_test.go | 6 +- cli/command/manifest/rm.go | 3 +- cli/command/network/connect_test.go | 5 +- cli/command/network/create.go | 18 +++--- cli/command/network/create_test.go | 5 +- cli/command/network/disconnect_test.go | 5 +- cli/command/network/list_test.go | 5 +- cli/command/network/prune.go | 3 +- cli/command/network/prune_test.go | 2 +- cli/command/network/remove_test.go | 3 +- cli/command/node/demote_test.go | 11 ++-- cli/command/node/inspect_test.go | 12 ++-- cli/command/node/list_test.go | 7 ++- cli/command/node/promote_test.go | 11 ++-- cli/command/node/ps.go | 5 +- cli/command/node/ps_test.go | 8 +-- cli/command/node/remove.go | 4 +- cli/command/node/remove_test.go | 5 +- cli/command/node/update.go | 5 +- cli/command/node/update_test.go | 17 ++--- cli/command/plugin/create.go | 4 +- cli/command/plugin/enable.go | 4 +- cli/command/plugin/install.go | 7 ++- cli/command/plugin/push.go | 5 +- cli/command/plugin/upgrade.go | 11 ++-- cli/command/plugin/upgrade_test.go | 3 +- cli/command/registry.go | 5 +- cli/command/registry/login.go | 7 ++- cli/command/secret/create.go | 6 +- cli/command/secret/create_test.go | 19 +++--- cli/command/secret/inspect_test.go | 8 +-- cli/command/secret/ls_test.go | 5 +- cli/command/secret/remove.go | 4 +- cli/command/secret/remove_test.go | 7 ++- cli/command/service/formatter.go | 3 +- cli/command/service/generic_resource_opts.go | 4 +- cli/command/service/inspect.go | 11 ++-- cli/command/service/logs.go | 11 ++-- cli/command/service/opts.go | 15 ++--- cli/command/service/parse.go | 12 ++-- cli/command/service/ps.go | 3 +- cli/command/service/remove.go | 3 +- cli/command/service/scale.go | 7 ++- cli/command/service/trust.go | 12 ++-- cli/command/service/update.go | 13 ++-- cli/command/stack/list_test.go | 5 +- cli/command/stack/loader/loader.go | 6 +- cli/command/stack/ps_test.go | 5 +- cli/command/stack/services_test.go | 9 +-- cli/command/stack/swarm/deploy.go | 5 +- .../stack/swarm/deploy_composefile_test.go | 3 +- cli/command/stack/swarm/list.go | 4 +- cli/command/stack/swarm/remove.go | 2 +- cli/command/swarm/ca.go | 3 +- cli/command/swarm/init.go | 7 ++- cli/command/swarm/init_test.go | 12 ++-- cli/command/swarm/join.go | 4 +- cli/command/swarm/join_test.go | 7 ++- cli/command/swarm/join_token.go | 3 +- cli/command/swarm/join_token_test.go | 12 ++-- cli/command/swarm/leave_test.go | 5 +- cli/command/swarm/opts.go | 9 +-- cli/command/swarm/unlock.go | 3 +- cli/command/swarm/unlock_key.go | 5 +- cli/command/swarm/unlock_key_test.go | 8 +-- cli/command/swarm/unlock_test.go | 7 ++- cli/command/swarm/update.go | 4 +- cli/command/swarm/update_test.go | 24 +++---- cli/command/system/dial_stdio.go | 8 ++- cli/command/system/inspect.go | 6 +- cli/command/system/prune.go | 3 +- cli/command/system/prune_test.go | 3 +- cli/command/telemetry_docker.go | 5 +- cli/command/telemetry_utils.go | 3 +- cli/command/trust/key_generate.go | 6 +- cli/command/trust/key_load.go | 9 +-- cli/command/trust/revoke.go | 5 +- cli/command/trust/sign.go | 7 ++- cli/command/trust/signer_add.go | 11 ++-- cli/command/trust/signer_remove.go | 11 ++-- cli/command/utils.go | 11 ++-- cli/command/utils_test.go | 3 +- cli/command/volume/create.go | 4 +- cli/command/volume/create_test.go | 16 ++--- cli/command/volume/inspect_test.go | 8 +-- cli/command/volume/list_test.go | 5 +- cli/command/volume/prune.go | 3 +- cli/command/volume/prune_test.go | 5 +- cli/command/volume/remove.go | 4 +- cli/command/volume/remove_test.go | 5 +- cli/command/volume/update.go | 3 +- cli/compose/convert/service.go | 30 ++++----- cli/compose/convert/service_test.go | 3 +- cli/compose/convert/volume.go | 7 ++- cli/compose/interpolation/interpolation.go | 5 +- cli/compose/loader/interpolate.go | 4 +- cli/compose/loader/loader.go | 49 ++++++++------- cli/compose/loader/merge.go | 24 +++---- cli/compose/loader/volume.go | 5 +- cli/compose/schema/schema.go | 3 +- cli/config/config.go | 7 +-- cli/config/configfile/file.go | 12 ++-- cli/config/credentials/native_store_test.go | 4 +- cli/connhelper/commandconn/commandconn.go | 5 +- cli/connhelper/connhelper.go | 4 +- cli/connhelper/ssh/ssh.go | 12 ++-- cli/context/docker/load.go | 7 ++- cli/context/store/metadatastore.go | 10 +-- cli/context/store/store.go | 8 +-- cli/context/store/tlsstore.go | 14 ++--- cli/context/tlsdata.go | 7 ++- cli/manifest/store/store.go | 4 +- cli/manifest/types/types.go | 6 +- cli/registry/client/client.go | 8 +-- cli/registry/client/endpoint.go | 4 +- cli/registry/client/fetcher.go | 18 +++--- cli/required.go | 15 ++--- cli/trust/trust.go | 29 ++++----- cmd/docker/aliases.go | 7 ++- cmd/docker/builder.go | 5 +- cmd/docker/docker.go | 5 +- docs/generate/generate.go | 6 +- e2e/testutils/plugins.go | 4 +- internal/test/environment/testenv.go | 3 +- internal/test/output/output.go | 11 ++-- opts/duration.go | 5 +- opts/env.go | 3 +- opts/gpus.go | 3 +- opts/opts.go | 2 +- service/logs/parse_logs.go | 3 +- 212 files changed, 838 insertions(+), 707 deletions(-) diff --git a/cli-plugins/manager/error.go b/cli-plugins/manager/error.go index f7dc6c7c55..2ffbf4ee7c 100644 --- a/cli-plugins/manager/error.go +++ b/cli-plugins/manager/error.go @@ -4,7 +4,7 @@ package manager import ( - "github.com/pkg/errors" + "fmt" ) // pluginError is set as Plugin.Err by NewPlugin if the plugin @@ -44,11 +44,11 @@ func wrapAsPluginError(err error, msg string) error { if err == nil { return nil } - return &pluginError{cause: errors.Wrap(err, msg)} + return &pluginError{cause: fmt.Errorf(msg+": %w", err)} } // NewPluginError creates a new pluginError, analogous to // errors.Errorf. func NewPluginError(msg string, args ...any) error { - return &pluginError{cause: errors.Errorf(msg, args...)} + return &pluginError{cause: fmt.Errorf(msg, args...)} } diff --git a/cli-plugins/manager/plugin.go b/cli-plugins/manager/plugin.go index 877241e0b8..2c0ff43438 100644 --- a/cli-plugins/manager/plugin.go +++ b/cli-plugins/manager/plugin.go @@ -3,13 +3,14 @@ package manager import ( "context" "encoding/json" + "errors" + "fmt" "os" "os/exec" "path/filepath" "regexp" "strings" - "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -44,14 +45,14 @@ func newPlugin(c Candidate, cmds []*cobra.Command) (Plugin, error) { // which would fail here, so there are all real errors. fullname := filepath.Base(path) if fullname == "." { - return Plugin{}, errors.Errorf("unable to determine basename of plugin candidate %q", path) + return Plugin{}, fmt.Errorf("unable to determine basename of plugin candidate %q", path) } var err error if fullname, err = trimExeSuffix(fullname); err != nil { - return Plugin{}, errors.Wrapf(err, "plugin candidate %q", path) + return Plugin{}, fmt.Errorf("plugin candidate %q: %w", path, err) } if !strings.HasPrefix(fullname, NamePrefix) { - return Plugin{}, errors.Errorf("plugin candidate %q: does not have %q prefix", path, NamePrefix) + return Plugin{}, fmt.Errorf("plugin candidate %q: does not have %q prefix", path, NamePrefix) } p := Plugin{ diff --git a/cli-plugins/manager/suffix_windows.go b/cli-plugins/manager/suffix_windows.go index 53b507c87d..fa846884e1 100644 --- a/cli-plugins/manager/suffix_windows.go +++ b/cli-plugins/manager/suffix_windows.go @@ -1,22 +1,21 @@ package manager import ( + "fmt" "path/filepath" "strings" - - "github.com/pkg/errors" ) // This is made slightly more complex due to needing to be case insensitive. func trimExeSuffix(s string) (string, error) { ext := filepath.Ext(s) if ext == "" { - return "", errors.Errorf("path %q lacks required file extension", s) + return "", fmt.Errorf("path %q lacks required file extension", s) } exe := ".exe" if !strings.EqualFold(ext, exe) { - return "", errors.Errorf("path %q lacks required %q suffix", s, exe) + return "", fmt.Errorf("path %q lacks required %q suffix", s, exe) } return strings.TrimSuffix(s, ext), nil } diff --git a/cli/cobra.go b/cli/cobra.go index feab2b4a91..ee35f38e90 100644 --- a/cli/cobra.go +++ b/cli/cobra.go @@ -15,7 +15,7 @@ import ( "github.com/fvbommel/sortorder" "github.com/moby/term" "github.com/morikuni/aec" - "github.com/pkg/errors" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -214,7 +214,7 @@ var helpCommand = &cobra.Command{ RunE: func(c *cobra.Command, args []string) error { cmd, args, e := c.Root().Find(args) if cmd == nil || e != nil || len(args) > 0 { - return errors.Errorf("unknown help topic: %v", strings.Join(args, " ")) + return fmt.Errorf("unknown help topic: %v", strings.Join(args, " ")) } helpFunc := cmd.HelpFunc() helpFunc(cmd, args) diff --git a/cli/command/checkpoint/create_test.go b/cli/command/checkpoint/create_test.go index b3b7372080..88f7db4547 100644 --- a/cli/command/checkpoint/create_test.go +++ b/cli/command/checkpoint/create_test.go @@ -1,13 +1,14 @@ package checkpoint import ( + "fmt" "io" "strings" "testing" "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/checkpoint" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -29,7 +30,7 @@ func TestCheckpointCreateErrors(t *testing.T) { { args: []string{"foo", "bar"}, checkpointCreateFunc: func(container string, options checkpoint.CreateOptions) error { - return errors.Errorf("error creating checkpoint for container foo") + return fmt.Errorf("error creating checkpoint for container foo") }, expectedError: "error creating checkpoint for container foo", }, diff --git a/cli/command/checkpoint/list_test.go b/cli/command/checkpoint/list_test.go index 437cc1b359..91690a2990 100644 --- a/cli/command/checkpoint/list_test.go +++ b/cli/command/checkpoint/list_test.go @@ -1,12 +1,13 @@ package checkpoint import ( + "fmt" "io" "testing" "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/checkpoint" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -29,7 +30,7 @@ func TestCheckpointListErrors(t *testing.T) { { args: []string{"foo"}, checkpointListFunc: func(container string, options checkpoint.ListOptions) ([]checkpoint.Summary, error) { - return []checkpoint.Summary{}, errors.Errorf("error getting checkpoints for container foo") + return []checkpoint.Summary{}, fmt.Errorf("error getting checkpoints for container foo") }, expectedError: "error getting checkpoints for container foo", }, diff --git a/cli/command/checkpoint/remove_test.go b/cli/command/checkpoint/remove_test.go index ae8402edb2..ed712df58c 100644 --- a/cli/command/checkpoint/remove_test.go +++ b/cli/command/checkpoint/remove_test.go @@ -1,12 +1,13 @@ package checkpoint import ( + "fmt" "io" "testing" "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/checkpoint" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -28,7 +29,7 @@ func TestCheckpointRemoveErrors(t *testing.T) { { args: []string{"foo", "bar"}, checkpointDeleteFunc: func(container string, options checkpoint.DeleteOptions) error { - return errors.Errorf("error deleting checkpoint") + return fmt.Errorf("error deleting checkpoint") }, expectedError: "error deleting checkpoint", }, diff --git a/cli/command/cli.go b/cli/command/cli.go index dacd1a1109..598974481f 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -5,6 +5,7 @@ package command import ( "context" + "errors" "fmt" "io" "os" @@ -33,7 +34,7 @@ import ( "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" "github.com/docker/go-connections/tlsconfig" - "github.com/pkg/errors" + "github.com/spf13/cobra" notaryclient "github.com/theupdateframework/notary/client" ) @@ -177,7 +178,7 @@ func (cli *DockerCli) BuildKitEnabled() (bool, error) { if v := os.Getenv("DOCKER_BUILDKIT"); v != "" { enabled, err := strconv.ParseBool(v) if err != nil { - return false, errors.Wrap(err, "DOCKER_BUILDKIT environment variable expects boolean value") + return false, fmt.Errorf("DOCKER_BUILDKIT environment variable expects boolean value: %w", err) } return enabled, nil } @@ -311,7 +312,7 @@ func NewAPIClientFromFlags(opts *cliflags.ClientOptions, configFile *configfile. } endpoint, err := resolveDockerEndpoint(contextStore, resolveContextName(opts, configFile)) if err != nil { - return nil, errors.Wrap(err, "unable to resolve docker endpoint") + return nil, fmt.Errorf("unable to resolve docker endpoint: %w", err) } return newAPIClientFromEndpoint(endpoint, configFile) } @@ -492,7 +493,7 @@ func (cli *DockerCli) initialize() error { cli.init.Do(func() { cli.dockerEndpoint, cli.initErr = cli.getDockerEndPoint() if cli.initErr != nil { - cli.initErr = errors.Wrap(cli.initErr, "unable to resolve docker endpoint") + cli.initErr = fmt.Errorf("unable to resolve docker endpoint: %w", cli.initErr) return } if cli.client == nil { diff --git a/cli/command/cli_options.go b/cli/command/cli_options.go index 84b121f34a..323891f17e 100644 --- a/cli/command/cli_options.go +++ b/cli/command/cli_options.go @@ -3,6 +3,7 @@ package command import ( "context" "encoding/csv" + "fmt" "io" "net/http" "os" @@ -13,7 +14,6 @@ import ( "github.com/docker/docker/client" "github.com/docker/docker/errdefs" "github.com/moby/term" - "github.com/pkg/errors" ) // CLIOption is a functional argument to apply options to a [DockerCli]. These @@ -177,7 +177,7 @@ func withCustomHeadersFromEnv() client.Opt { csvReader := csv.NewReader(strings.NewReader(value)) fields, err := csvReader.Read() if err != nil { - return errdefs.InvalidParameter(errors.Errorf("failed to parse custom headers from %s environment variable: value must be formatted as comma-separated key=value pairs", envOverrideHTTPHeaders)) + return errdefs.InvalidParameter(fmt.Errorf("failed to parse custom headers from %s environment variable: value must be formatted as comma-separated key=value pairs", envOverrideHTTPHeaders)) } if len(fields) == 0 { return nil @@ -191,7 +191,7 @@ func withCustomHeadersFromEnv() client.Opt { k = strings.TrimSpace(k) if k == "" { - return errdefs.InvalidParameter(errors.Errorf(`failed to set custom headers from %s environment variable: value contains a key=value pair with an empty key: '%s'`, envOverrideHTTPHeaders, kv)) + return errdefs.InvalidParameter(fmt.Errorf(`failed to set custom headers from %s environment variable: value contains a key=value pair with an empty key: '%s'`, envOverrideHTTPHeaders, kv)) } // We don't currently allow empty key=value pairs, and produce an error. @@ -199,7 +199,7 @@ func withCustomHeadersFromEnv() client.Opt { // from an environment variable with the same name). In the meantime, // produce an error to prevent users from depending on this. if !hasValue { - return errdefs.InvalidParameter(errors.Errorf(`failed to set custom headers from %s environment variable: missing "=" in key=value pair: '%s'`, envOverrideHTTPHeaders, kv)) + return errdefs.InvalidParameter(fmt.Errorf(`failed to set custom headers from %s environment variable: missing "=" in key=value pair: '%s'`, envOverrideHTTPHeaders, kv)) } env[http.CanonicalHeaderKey(k)] = v diff --git a/cli/command/cli_test.go b/cli/command/cli_test.go index 2d12974d93..899d76a1ca 100644 --- a/cli/command/cli_test.go +++ b/cli/command/cli_test.go @@ -3,6 +3,7 @@ package command import ( "bytes" "context" + "errors" "fmt" "io" "net" @@ -22,7 +23,7 @@ import ( "github.com/docker/docker/api" "github.com/docker/docker/api/types" "github.com/docker/docker/client" - "github.com/pkg/errors" + "gotest.tools/v3/assert" "gotest.tools/v3/fs" ) diff --git a/cli/command/config/create.go b/cli/command/config/create.go index 965d2ddc74..232b4f3fb6 100644 --- a/cli/command/config/create.go +++ b/cli/command/config/create.go @@ -11,7 +11,7 @@ import ( "github.com/docker/cli/opts" "github.com/docker/docker/api/types/swarm" "github.com/moby/sys/sequential" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -63,7 +63,7 @@ func RunConfigCreate(ctx context.Context, dockerCli command.Cli, options CreateO configData, err := io.ReadAll(in) if err != nil { - return errors.Errorf("Error reading content from %q: %v", options.File, err) + return fmt.Errorf("Error reading content from %q: %v", options.File, err) } spec := swarm.ConfigSpec{ diff --git a/cli/command/config/create_test.go b/cli/command/config/create_test.go index 848f9c6e07..488d5ac5c2 100644 --- a/cli/command/config/create_test.go +++ b/cli/command/config/create_test.go @@ -2,6 +2,7 @@ package config import ( "context" + "fmt" "io" "os" "path/filepath" @@ -12,7 +13,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -37,7 +38,7 @@ func TestConfigCreateErrors(t *testing.T) { { args: []string{"name", filepath.Join("testdata", configDataFile)}, configCreateFunc: func(_ context.Context, configSpec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { - return types.ConfigCreateResponse{}, errors.Errorf("error creating config") + return types.ConfigCreateResponse{}, fmt.Errorf("error creating config") }, expectedError: "error creating config", }, @@ -64,7 +65,7 @@ func TestConfigCreateWithName(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { if spec.Name != name { - return types.ConfigCreateResponse{}, errors.Errorf("expected name %q, got %q", name, spec.Name) + return types.ConfigCreateResponse{}, fmt.Errorf("expected name %q, got %q", name, spec.Name) } actual = spec.Data @@ -103,7 +104,7 @@ func TestConfigCreateWithLabels(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { if !reflect.DeepEqual(spec, expected) { - return types.ConfigCreateResponse{}, errors.Errorf("expected %+v, got %+v", expected, spec) + return types.ConfigCreateResponse{}, fmt.Errorf("expected %+v, got %+v", expected, spec) } return types.ConfigCreateResponse{ @@ -129,11 +130,11 @@ func TestConfigCreateWithTemplatingDriver(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ configCreateFunc: func(_ context.Context, spec swarm.ConfigSpec) (types.ConfigCreateResponse, error) { if spec.Name != name { - return types.ConfigCreateResponse{}, errors.Errorf("expected name %q, got %q", name, spec.Name) + return types.ConfigCreateResponse{}, fmt.Errorf("expected name %q, got %q", name, spec.Name) } if spec.Templating.Name != expectedDriver.Name { - return types.ConfigCreateResponse{}, errors.Errorf("expected driver %v, got %v", expectedDriver, spec.Labels) + return types.ConfigCreateResponse{}, fmt.Errorf("expected driver %v, got %v", expectedDriver, spec.Labels) } return types.ConfigCreateResponse{ diff --git a/cli/command/config/inspect_test.go b/cli/command/config/inspect_test.go index fc22516fbb..432f62dd3c 100644 --- a/cli/command/config/inspect_test.go +++ b/cli/command/config/inspect_test.go @@ -10,7 +10,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -28,7 +28,7 @@ func TestConfigInspectErrors(t *testing.T) { { args: []string{"foo"}, configInspectFunc: func(_ context.Context, configID string) (swarm.Config, []byte, error) { - return swarm.Config{}, nil, errors.Errorf("error while inspecting the config") + return swarm.Config{}, nil, fmt.Errorf("error while inspecting the config") }, expectedError: "error while inspecting the config", }, @@ -45,7 +45,7 @@ func TestConfigInspectErrors(t *testing.T) { if configID == "foo" { return *builders.Config(builders.ConfigName("foo")), nil, nil } - return swarm.Config{}, nil, errors.Errorf("error while inspecting the config") + return swarm.Config{}, nil, fmt.Errorf("error while inspecting the config") }, expectedError: "error while inspecting the config", }, @@ -77,7 +77,7 @@ func TestConfigInspectWithoutFormat(t *testing.T) { args: []string{"foo"}, configInspectFunc: func(_ context.Context, name string) (swarm.Config, []byte, error) { if name != "foo" { - return swarm.Config{}, nil, errors.Errorf("Invalid name, expected %s, got %s", "foo", name) + return swarm.Config{}, nil, fmt.Errorf("Invalid name, expected %s, got %s", "foo", name) } return *builders.Config(builders.ConfigID("ID-foo"), builders.ConfigName("foo")), nil, nil }, diff --git a/cli/command/config/ls_test.go b/cli/command/config/ls_test.go index 15658ee330..309a65544d 100644 --- a/cli/command/config/ls_test.go +++ b/cli/command/config/ls_test.go @@ -2,6 +2,7 @@ package config import ( "context" + "fmt" "io" "testing" "time" @@ -11,7 +12,7 @@ import ( "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -29,7 +30,7 @@ func TestConfigListErrors(t *testing.T) { }, { configListFunc: func(_ context.Context, options types.ConfigListOptions) ([]swarm.Config, error) { - return []swarm.Config{}, errors.Errorf("error listing configs") + return []swarm.Config{}, fmt.Errorf("error listing configs") }, expectedError: "error listing configs", }, diff --git a/cli/command/config/remove.go b/cli/command/config/remove.go index cd5403db05..59012fa1f5 100644 --- a/cli/command/config/remove.go +++ b/cli/command/config/remove.go @@ -7,7 +7,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -50,7 +50,7 @@ func RunConfigRemove(ctx context.Context, dockerCli command.Cli, opts RemoveOpti } if len(errs) > 0 { - return errors.Errorf("%s", strings.Join(errs, "\n")) + return fmt.Errorf("%s", strings.Join(errs, "\n")) } return nil diff --git a/cli/command/config/remove_test.go b/cli/command/config/remove_test.go index d1c5a71f9f..e70ccc4fb1 100644 --- a/cli/command/config/remove_test.go +++ b/cli/command/config/remove_test.go @@ -1,12 +1,13 @@ package config import ( + "fmt" "io" "strings" "testing" "github.com/docker/cli/internal/test" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -24,7 +25,7 @@ func TestConfigRemoveErrors(t *testing.T) { { args: []string{"foo"}, configRemoveFunc: func(name string) error { - return errors.Errorf("error removing config") + return fmt.Errorf("error removing config") }, expectedError: "error removing config", }, @@ -66,7 +67,7 @@ func TestConfigRemoveContinueAfterError(t *testing.T) { configRemoveFunc: func(name string) error { removedConfigs = append(removedConfigs, name) if name == "foo" { - return errors.Errorf("error removing config: %s", name) + return fmt.Errorf("error removing config: %s", name) } return nil }, diff --git a/cli/command/container/attach.go b/cli/command/container/attach.go index a4dbe0ec0d..67ab9a3a0d 100644 --- a/cli/command/container/attach.go +++ b/cli/command/container/attach.go @@ -2,6 +2,7 @@ package container import ( "context" + "errors" "io" "github.com/docker/cli/cli" @@ -10,7 +11,7 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" "github.com/moby/sys/signal" - "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cli/command/container/attach_test.go b/cli/command/container/attach_test.go index 2bbef24a8d..6cd1dd9beb 100644 --- a/cli/command/container/attach_test.go +++ b/cli/command/container/attach_test.go @@ -1,13 +1,15 @@ package container import ( + "errors" + "fmt" "io" "testing" "github.com/docker/cli/cli" "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/container" - "github.com/pkg/errors" + "gotest.tools/v3/assert" ) @@ -23,7 +25,7 @@ func TestNewAttachCommandErrors(t *testing.T) { args: []string{"5cb5bb5e4a3b"}, expectedError: "something went wrong", containerInspectFunc: func(containerID string) (container.InspectResponse, error) { - return container.InspectResponse{}, errors.Errorf("something went wrong") + return container.InspectResponse{}, fmt.Errorf("something went wrong") }, }, { diff --git a/cli/command/container/commit_test.go b/cli/command/container/commit_test.go index a9127035a2..b1c2403909 100644 --- a/cli/command/container/commit_test.go +++ b/cli/command/container/commit_test.go @@ -2,13 +2,14 @@ package container import ( "context" + "errors" "io" "testing" "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) diff --git a/cli/command/container/cp.go b/cli/command/container/cp.go index b361e2678c..d2ee235442 100644 --- a/cli/command/container/cp.go +++ b/cli/command/container/cp.go @@ -3,6 +3,7 @@ package container import ( "bytes" "context" + "errors" "fmt" "io" "os" @@ -20,7 +21,7 @@ import ( "github.com/docker/docker/pkg/system" units "github.com/docker/go-units" "github.com/morikuni/aec" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -331,7 +332,7 @@ func copyToContainer(ctx context.Context, dockerCli command.Cli, copyConfig cpCo // Validate the destination path if err := command.ValidateOutputPathFileMode(dstStat.Mode); err != nil { - return errors.Wrapf(err, `destination "%s:%s" must be a directory or a regular file`, copyConfig.container, dstPath) + return fmt.Errorf("destination \"%s:%s\" must be a directory or a regular file: %w", copyConfig.container, dstPath, err) } // Ignore any error and assume that the parent directory of the destination @@ -354,7 +355,7 @@ func copyToContainer(ctx context.Context, dockerCli command.Cli, copyConfig cpCo content = os.Stdin resolvedDstPath = dstInfo.Path if !dstInfo.IsDir { - return errors.Errorf("destination \"%s:%s\" must be a directory", copyConfig.container, dstPath) + return fmt.Errorf("destination \"%s:%s\" must be a directory", copyConfig.container, dstPath) } } else { // Prepare source copy info. diff --git a/cli/command/container/create.go b/cli/command/container/create.go index 31ddeaad01..4a6caa0804 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -21,7 +21,7 @@ import ( "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/jsonmessage" specs "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/pkg/errors" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -168,7 +168,7 @@ func (cid *cidFile) Close() error { return nil } if err := os.Remove(cid.path); err != nil { - return errors.Wrapf(err, "failed to remove the CID file '%s'", cid.path) + return fmt.Errorf("failed to remove the CID file '%s': %w", cid.path, err) } return nil @@ -179,7 +179,7 @@ func (cid *cidFile) Write(id string) error { return nil } if _, err := cid.file.Write([]byte(id)); err != nil { - return errors.Wrap(err, "failed to write the container ID to the file") + return fmt.Errorf("failed to write the container ID to the file: %w", err) } cid.written = true return nil @@ -190,12 +190,12 @@ func newCIDFile(path string) (*cidFile, error) { return &cidFile{}, nil } if _, err := os.Stat(path); err == nil { - return nil, errors.Errorf("container ID file found, make sure the other container isn't running or delete %s", path) + return nil, fmt.Errorf("container ID file found, make sure the other container isn't running or delete %s", path) } f, err := os.Create(path) if err != nil { - return nil, errors.Wrap(err, "failed to create the container ID file") + return nil, fmt.Errorf("failed to create the container ID file: %w", err) } return &cidFile{path: path, file: f}, nil @@ -256,7 +256,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c if options.platform != "" && versions.GreaterThanOrEqualTo(dockerCli.Client().ClientVersion(), "1.41") { p, err := platforms.Parse(options.platform) if err != nil { - return "", errors.Wrap(errdefs.InvalidParameter(err), "error parsing specified platform") + return "", fmt.Errorf("error parsing specified platform: %w", errdefs.InvalidParameter(err)) } platform = &p } diff --git a/cli/command/container/diff.go b/cli/command/container/diff.go index 15699f5dbb..2167361840 100644 --- a/cli/command/container/diff.go +++ b/cli/command/container/diff.go @@ -2,12 +2,13 @@ package container import ( "context" + "errors" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" "github.com/docker/cli/cli/command/formatter" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/container/diff_test.go b/cli/command/container/diff_test.go index 2fb191fe81..fbfebea3b7 100644 --- a/cli/command/container/diff_test.go +++ b/cli/command/container/diff_test.go @@ -2,13 +2,14 @@ package container import ( "context" + "errors" "io" "strings" "testing" "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/container" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) diff --git a/cli/command/container/exec.go b/cli/command/container/exec.go index c2a1d44799..31ed331561 100644 --- a/cli/command/container/exec.go +++ b/cli/command/container/exec.go @@ -2,6 +2,7 @@ package container import ( "context" + "errors" "fmt" "io" @@ -12,7 +13,7 @@ import ( "github.com/docker/cli/opts" "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" - "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cli/command/container/exec_test.go b/cli/command/container/exec_test.go index 89193b29f4..99bea08790 100644 --- a/cli/command/container/exec_test.go +++ b/cli/command/container/exec_test.go @@ -2,6 +2,8 @@ package container import ( "context" + "errors" + "fmt" "io" "os" "testing" @@ -12,7 +14,7 @@ import ( "github.com/docker/cli/opts" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/fs" @@ -259,7 +261,7 @@ func TestNewExecCommandErrors(t *testing.T) { args: []string{"5cb5bb5e4a3b", "-t", "-i", "bash"}, expectedError: "something went wrong", containerInspectFunc: func(containerID string) (container.InspectResponse, error) { - return container.InspectResponse{}, errors.Errorf("something went wrong") + return container.InspectResponse{}, fmt.Errorf("something went wrong") }, }, } diff --git a/cli/command/container/export.go b/cli/command/container/export.go index e9afa7dbe1..f7f13ad059 100644 --- a/cli/command/container/export.go +++ b/cli/command/container/export.go @@ -2,12 +2,14 @@ package container import ( "context" + "errors" + "fmt" "io" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -47,7 +49,7 @@ func runExport(ctx context.Context, dockerCli command.Cli, opts exportOptions) e } if err := command.ValidateOutputPath(opts.output); err != nil { - return errors.Wrap(err, "failed to export container") + return fmt.Errorf("failed to export container: %w", err) } clnt := dockerCli.Client() diff --git a/cli/command/container/kill.go b/cli/command/container/kill.go index 0095198b5a..6d8fbe0b96 100644 --- a/cli/command/container/kill.go +++ b/cli/command/container/kill.go @@ -2,13 +2,14 @@ package container import ( "context" + "errors" "fmt" "strings" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/container/list.go b/cli/command/container/list.go index 4523fe51d2..0a68958f27 100644 --- a/cli/command/container/list.go +++ b/cli/command/container/list.go @@ -2,6 +2,7 @@ package container import ( "context" + "fmt" "io" "github.com/docker/cli/cli" @@ -12,7 +13,7 @@ import ( "github.com/docker/cli/opts" "github.com/docker/cli/templates" "github.com/docker/docker/api/types/container" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -84,7 +85,7 @@ func buildContainerListOptions(options *psOptions) (*container.ListOptions, erro if len(options.format) > 0 { tmpl, err := templates.NewParse("", options.format) if err != nil { - return nil, errors.Wrap(err, "failed to parse template") + return nil, fmt.Errorf("failed to parse template: %w", err) } optionsProcessor := formatter.NewContainerContext() @@ -92,7 +93,7 @@ func buildContainerListOptions(options *psOptions) (*container.ListOptions, erro // This shouldn't error out but swallowing the error makes it harder // to track down if preProcessor issues come up. if err := tmpl.Execute(io.Discard, optionsProcessor); err != nil { - return nil, errors.Wrap(err, "failed to execute template") + return nil, fmt.Errorf("failed to execute template: %w", err) } // if `size` was not explicitly set to false (with `--size=false`) diff --git a/cli/command/container/opts.go b/cli/command/container/opts.go index 2106884898..b31ca943ab 100644 --- a/cli/command/container/opts.go +++ b/cli/command/container/opts.go @@ -3,6 +3,7 @@ package container import ( "bytes" "encoding/json" + "errors" "fmt" "os" "path" @@ -22,7 +23,7 @@ import ( "github.com/docker/docker/api/types/strslice" "github.com/docker/docker/errdefs" "github.com/docker/go-connections/nat" - "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/spf13/pflag" cdi "tags.cncf.io/container-device-interface/pkg/parser" @@ -345,7 +346,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con // Validate the input mac address if copts.macAddress != "" { if _, err := opts.ValidateMACAddress(copts.macAddress); err != nil { - return nil, errors.Errorf("%s is not a valid mac address", copts.macAddress) + return nil, fmt.Errorf("%s is not a valid mac address", copts.macAddress) } } if copts.stdin { @@ -361,7 +362,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con swappiness := copts.swappiness if swappiness != -1 && (swappiness < 0 || swappiness > 100) { - return nil, errors.Errorf("invalid value: %d. Valid memory swappiness range is 0-100", swappiness) + return nil, fmt.Errorf("invalid value: %d. Valid memory swappiness range is 0-100", swappiness) } mounts := copts.mounts.Value() @@ -443,7 +444,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con // Merge in exposed ports to the map of published ports for _, e := range copts.expose.GetAll() { if strings.Contains(e, ":") { - return nil, errors.Errorf("invalid port format for --expose: %s", e) + return nil, fmt.Errorf("invalid port format for --expose: %s", e) } // support two formats for expose, original format /[] // or /[] @@ -452,7 +453,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con // if expose a port, the start and end port are the same start, end, err := nat.ParsePortRange(port) if err != nil { - return nil, errors.Errorf("invalid range format for --expose: %s, error: %s", e, err) + return nil, fmt.Errorf("invalid range format for --expose: %s, error: %s", e, err) } for i := start; i <= end; i++ { p, err := nat.NewPort(proto, strconv.FormatUint(i, 10)) @@ -506,22 +507,22 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con pidMode := container.PidMode(copts.pidMode) if !pidMode.Valid() { - return nil, errors.Errorf("--pid: invalid PID mode") + return nil, fmt.Errorf("--pid: invalid PID mode") } utsMode := container.UTSMode(copts.utsMode) if !utsMode.Valid() { - return nil, errors.Errorf("--uts: invalid UTS mode") + return nil, fmt.Errorf("--uts: invalid UTS mode") } usernsMode := container.UsernsMode(copts.usernsMode) if !usernsMode.Valid() { - return nil, errors.Errorf("--userns: invalid USER mode") + return nil, fmt.Errorf("--userns: invalid USER mode") } cgroupnsMode := container.CgroupnsMode(copts.cgroupnsMode) if !cgroupnsMode.Valid() { - return nil, errors.Errorf("--cgroupns: invalid CGROUP mode") + return nil, fmt.Errorf("--cgroupns: invalid CGROUP mode") } restartPolicy, err := opts.ParseRestartPolicy(copts.restartPolicy) @@ -556,7 +557,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con copts.healthStartInterval != 0 if copts.noHealthcheck { if haveHealthSettings { - return nil, errors.Errorf("--no-healthcheck conflicts with --health-* options") + return nil, fmt.Errorf("--no-healthcheck conflicts with --health-* options") } healthConfig = &container.HealthConfig{Test: strslice.StrSlice{"NONE"}} } else if haveHealthSettings { @@ -565,13 +566,13 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con probe = []string{"CMD-SHELL", copts.healthCmd} } if copts.healthInterval < 0 { - return nil, errors.Errorf("--health-interval cannot be negative") + return nil, fmt.Errorf("--health-interval cannot be negative") } if copts.healthTimeout < 0 { - return nil, errors.Errorf("--health-timeout cannot be negative") + return nil, fmt.Errorf("--health-timeout cannot be negative") } if copts.healthRetries < 0 { - return nil, errors.Errorf("--health-retries cannot be negative") + return nil, fmt.Errorf("--health-retries cannot be negative") } if copts.healthStartPeriod < 0 { return nil, errors.New("--health-start-period cannot be negative") @@ -704,7 +705,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con } if copts.autoRemove && !hostConfig.RestartPolicy.IsNone() { - return nil, errors.Errorf("conflicting options: cannot specify both --restart and --rm") + return nil, fmt.Errorf("conflicting options: cannot specify both --restart and --rm") } // only set this value if the user provided the flag, else it should default to nil @@ -788,7 +789,7 @@ func parseNetworkOpts(copts *containerOptions) (map[string]*networktypes.Endpoin return nil, err } if _, ok := endpoints[n.Target]; ok { - return nil, errdefs.InvalidParameter(errors.Errorf("network %q is specified multiple times", n.Target)) + return nil, errdefs.InvalidParameter(fmt.Errorf("network %q is specified multiple times", n.Target)) } // For backward compatibility: if no custom options are provided for the network, @@ -882,7 +883,7 @@ func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*networktypes.End } if ep.MacAddress != "" { if _, err := opts.ValidateMACAddress(ep.MacAddress); err != nil { - return nil, errors.Errorf("%s is not a valid mac address", ep.MacAddress) + return nil, fmt.Errorf("%s is not a valid mac address", ep.MacAddress) } epConfig.MacAddress = ep.MacAddress } @@ -897,7 +898,7 @@ func convertToStandardNotation(ports []string) ([]string, error) { for _, param := range strings.Split(publish, ",") { k, v, ok := strings.Cut(param, "=") if !ok || k == "" { - return optsList, errors.Errorf("invalid publish opts format (should be name=value but got '%s')", param) + return optsList, fmt.Errorf("invalid publish opts format (should be name=value but got '%s')", param) } params[k] = v } @@ -912,7 +913,7 @@ func convertToStandardNotation(ports []string) ([]string, error) { func parseLoggingOpts(loggingDriver string, loggingOpts []string) (map[string]string, error) { loggingOptsMap := opts.ConvertKVStringsToMap(loggingOpts) if loggingDriver == "none" && len(loggingOpts) > 0 { - return map[string]string{}, errors.Errorf("invalid logging opts for driver %s", loggingDriver) + return map[string]string{}, fmt.Errorf("invalid logging opts for driver %s", loggingDriver) } return loggingOptsMap, nil } @@ -926,7 +927,7 @@ func parseSecurityOpts(securityOpts []string) ([]string, error) { } if (!ok || v == "") && k != "no-new-privileges" { // "no-new-privileges" is the only option that does not require a value. - return securityOpts, errors.Errorf("Invalid --security-opt: %q", opt) + return securityOpts, fmt.Errorf("Invalid --security-opt: %q", opt) } if k == "seccomp" { switch v { @@ -937,11 +938,11 @@ func parseSecurityOpts(securityOpts []string) ([]string, error) { // content if it's valid JSON. f, err := os.ReadFile(v) if err != nil { - return securityOpts, errors.Errorf("opening seccomp profile (%s) failed: %v", v, err) + return securityOpts, fmt.Errorf("opening seccomp profile (%s) failed: %v", v, err) } b := bytes.NewBuffer(nil) if err := json.Compact(b, f); err != nil { - return securityOpts, errors.Errorf("compacting json for seccomp profile (%s) failed: %v", v, err) + return securityOpts, fmt.Errorf("compacting json for seccomp profile (%s) failed: %v", v, err) } securityOpts[key] = fmt.Sprintf("seccomp=%s", b.Bytes()) } @@ -976,7 +977,7 @@ func parseStorageOpts(storageOpts []string) (map[string]string, error) { for _, option := range storageOpts { k, v, ok := strings.Cut(option, "=") if !ok { - return nil, errors.Errorf("invalid storage option") + return nil, fmt.Errorf("invalid storage option") } m[k] = v } @@ -991,7 +992,7 @@ func parseDevice(device, serverOS string) (container.DeviceMapping, error) { case "windows": return parseWindowsDevice(device) } - return container.DeviceMapping{}, errors.Errorf("unknown server OS: %s", serverOS) + return container.DeviceMapping{}, fmt.Errorf("unknown server OS: %s", serverOS) } // parseLinuxDevice parses a device mapping string to a container.DeviceMapping struct @@ -1015,7 +1016,7 @@ func parseLinuxDevice(device string) (container.DeviceMapping, error) { case 1: src = arr[0] default: - return container.DeviceMapping{}, errors.Errorf("invalid device specification: %s", device) + return container.DeviceMapping{}, fmt.Errorf("invalid device specification: %s", device) } if dst == "" { @@ -1045,7 +1046,7 @@ func validateDeviceCgroupRule(val string) (string, error) { return val, nil } - return val, errors.Errorf("invalid device cgroup format '%s'", val) + return val, fmt.Errorf("invalid device cgroup format '%s'", val) } // validDeviceMode checks if the mode for device is valid or not. @@ -1077,7 +1078,7 @@ func validateDevice(val string, serverOS string) (string, error) { // Windows does validation entirely server-side return val, nil } - return "", errors.Errorf("unknown server OS: %s", serverOS) + return "", fmt.Errorf("unknown server OS: %s", serverOS) } // validateLinuxPath is the implementation of validateDevice knowing that the @@ -1092,12 +1093,12 @@ func validateLinuxPath(val string, validator func(string) bool) (string, error) var mode string if strings.Count(val, ":") > 2 { - return val, errors.Errorf("bad format for path: %s", val) + return val, fmt.Errorf("bad format for path: %s", val) } split := strings.SplitN(val, ":", 3) if split[0] == "" { - return val, errors.Errorf("bad format for path: %s", val) + return val, fmt.Errorf("bad format for path: %s", val) } switch len(split) { case 1: @@ -1116,13 +1117,13 @@ func validateLinuxPath(val string, validator func(string) bool) (string, error) containerPath = split[1] mode = split[2] if isValid := validator(split[2]); !isValid { - return val, errors.Errorf("bad mode specified: %s", mode) + return val, fmt.Errorf("bad mode specified: %s", mode) } val = fmt.Sprintf("%s:%s:%s", split[0], containerPath, mode) } if !path.IsAbs(containerPath) { - return val, errors.Errorf("%s is not an absolute path", containerPath) + return val, fmt.Errorf("%s is not an absolute path", containerPath) } return val, nil } @@ -1135,7 +1136,7 @@ func validateAttach(val string) (string, error) { return s, nil } } - return val, errors.Errorf("valid streams are STDIN, STDOUT and STDERR") + return val, fmt.Errorf("valid streams are STDIN, STDOUT and STDERR") } func validateAPIVersion(c *containerConfig, serverAPIVersion string) error { diff --git a/cli/command/container/opts_test.go b/cli/command/container/opts_test.go index e0ff746bc5..1e19a6d429 100644 --- a/cli/command/container/opts_test.go +++ b/cli/command/container/opts_test.go @@ -12,7 +12,7 @@ import ( "github.com/docker/docker/api/types/container" networktypes "github.com/docker/docker/api/types/network" "github.com/docker/go-connections/nat" - "github.com/pkg/errors" + "github.com/spf13/pflag" "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" @@ -280,7 +280,7 @@ func compareRandomizedStrings(a, b, c, d string) error { if a == d && b == c { return nil } - return errors.Errorf("strings don't match") + return fmt.Errorf("strings don't match") } // Simple parse with MacAddress validation diff --git a/cli/command/container/pause.go b/cli/command/container/pause.go index 87fb0e10c5..cad4494ecc 100644 --- a/cli/command/container/pause.go +++ b/cli/command/container/pause.go @@ -2,6 +2,7 @@ package container import ( "context" + "errors" "fmt" "strings" @@ -9,7 +10,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" "github.com/docker/docker/api/types/container" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/container/port.go b/cli/command/container/port.go index 915ecf057d..15151bfea3 100644 --- a/cli/command/container/port.go +++ b/cli/command/container/port.go @@ -13,7 +13,7 @@ import ( "github.com/docker/cli/cli/command/completion" "github.com/docker/go-connections/nat" "github.com/fvbommel/sortorder" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -65,11 +65,11 @@ func runPort(ctx context.Context, dockerCli command.Cli, opts *portOptions) erro proto = "tcp" } if _, err = strconv.ParseUint(port, 10, 16); err != nil { - return errors.Wrapf(err, "Error: invalid port (%s)", port) + return fmt.Errorf("Error: invalid port (%s): %w", port, err) } frontends, exists := c.NetworkSettings.Ports[nat.Port(port+"/"+proto)] if !exists || frontends == nil { - return errors.Errorf("Error: No public port '%s' published for %s", opts.port, opts.container) + return fmt.Errorf("Error: No public port '%s' published for %s", opts.port, opts.container) } for _, frontend := range frontends { out = append(out, net.JoinHostPort(frontend.HostIP, frontend.HostPort)) diff --git a/cli/command/container/prune.go b/cli/command/container/prune.go index 1c879002a8..65303a575e 100644 --- a/cli/command/container/prune.go +++ b/cli/command/container/prune.go @@ -2,6 +2,7 @@ package container import ( "context" + "errors" "fmt" "github.com/docker/cli/cli" @@ -10,7 +11,7 @@ import ( "github.com/docker/cli/opts" "github.com/docker/docker/errdefs" units "github.com/docker/go-units" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/container/prune_test.go b/cli/command/container/prune_test.go index bf2e793d07..23b6329c22 100644 --- a/cli/command/container/prune_test.go +++ b/cli/command/container/prune_test.go @@ -2,13 +2,13 @@ package container import ( "context" + "errors" "io" "testing" "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/filters" - "github.com/pkg/errors" ) func TestContainerPrunePromptTermination(t *testing.T) { diff --git a/cli/command/container/rename.go b/cli/command/container/rename.go index a871e38d1e..4e7f91afd6 100644 --- a/cli/command/container/rename.go +++ b/cli/command/container/rename.go @@ -2,13 +2,14 @@ package container import ( "context" + "errors" "fmt" "strings" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -48,7 +49,7 @@ func runRename(ctx context.Context, dockerCli command.Cli, opts *renameOptions) if err := dockerCli.Client().ContainerRename(ctx, oldName, newName); err != nil { fmt.Fprintln(dockerCli.Err(), err) - return errors.Errorf("Error: failed to rename container named %s", oldName) + return fmt.Errorf("Error: failed to rename container named %s", oldName) } return nil } diff --git a/cli/command/container/rename_test.go b/cli/command/container/rename_test.go index 4d9c3f664d..f1c9dc1f3a 100644 --- a/cli/command/container/rename_test.go +++ b/cli/command/container/rename_test.go @@ -2,11 +2,12 @@ package container import ( "context" + "errors" "io" "testing" "github.com/docker/cli/internal/test" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) diff --git a/cli/command/container/restart.go b/cli/command/container/restart.go index 5460ff5228..ce681ecb2e 100644 --- a/cli/command/container/restart.go +++ b/cli/command/container/restart.go @@ -2,6 +2,7 @@ package container import ( "context" + "errors" "fmt" "strings" @@ -9,7 +10,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" "github.com/docker/docker/api/types/container" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/container/restart_test.go b/cli/command/container/restart_test.go index d1b6ed43ea..3f617de518 100644 --- a/cli/command/container/restart_test.go +++ b/cli/command/container/restart_test.go @@ -2,6 +2,7 @@ package container import ( "context" + "errors" "io" "sort" "sync" @@ -10,7 +11,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/container" "github.com/docker/docker/errdefs" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) diff --git a/cli/command/container/rm.go b/cli/command/container/rm.go index 171e8e81e9..996cc04637 100644 --- a/cli/command/container/rm.go +++ b/cli/command/container/rm.go @@ -2,6 +2,7 @@ package container import ( "context" + "errors" "fmt" "strings" @@ -10,7 +11,7 @@ import ( "github.com/docker/cli/cli/command/completion" "github.com/docker/docker/api/types/container" "github.com/docker/docker/errdefs" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/container/run.go b/cli/command/container/run.go index a3fc5f983a..3d8f757ed0 100644 --- a/cli/command/container/run.go +++ b/cli/command/container/run.go @@ -2,6 +2,7 @@ package container import ( "context" + "errors" "fmt" "io" "strings" @@ -14,7 +15,7 @@ import ( "github.com/docker/docker/api/types/container" "github.com/moby/sys/signal" "github.com/moby/term" - "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/pflag" diff --git a/cli/command/container/start.go b/cli/command/container/start.go index 29aaa988d6..b9bf77e41e 100644 --- a/cli/command/container/start.go +++ b/cli/command/container/start.go @@ -2,6 +2,7 @@ package container import ( "context" + "errors" "fmt" "io" "strings" @@ -12,7 +13,7 @@ import ( "github.com/docker/docker/api/types/container" "github.com/moby/sys/signal" "github.com/moby/term" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -203,7 +204,7 @@ func startContainersWithoutAttachments(ctx context.Context, dockerCli command.Cl } if len(failedContainers) > 0 { - return errors.Errorf("Error: failed to start containers: %s", strings.Join(failedContainers, ", ")) + return fmt.Errorf("Error: failed to start containers: %s", strings.Join(failedContainers, ", ")) } return nil } diff --git a/cli/command/container/stats.go b/cli/command/container/stats.go index dd5e35d5fa..402cb76127 100644 --- a/cli/command/container/stats.go +++ b/cli/command/container/stats.go @@ -2,6 +2,7 @@ package container import ( "context" + "errors" "fmt" "io" "strings" @@ -16,7 +17,7 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/events" "github.com/docker/docker/api/types/filters" - "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) diff --git a/cli/command/container/stats_helpers.go b/cli/command/container/stats_helpers.go index c7084c17b5..6bb6c74d7c 100644 --- a/cli/command/container/stats_helpers.go +++ b/cli/command/container/stats_helpers.go @@ -3,13 +3,14 @@ package container import ( "context" "encoding/json" + "errors" "io" "sync" "time" "github.com/docker/docker/api/types/container" "github.com/docker/docker/client" - "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) diff --git a/cli/command/container/stop.go b/cli/command/container/stop.go index af24f43caf..e25624d52f 100644 --- a/cli/command/container/stop.go +++ b/cli/command/container/stop.go @@ -2,6 +2,7 @@ package container import ( "context" + "errors" "fmt" "strings" @@ -9,7 +10,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" "github.com/docker/docker/api/types/container" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/container/stop_test.go b/cli/command/container/stop_test.go index 1fad3cd05e..037e56e804 100644 --- a/cli/command/container/stop_test.go +++ b/cli/command/container/stop_test.go @@ -2,6 +2,7 @@ package container import ( "context" + "errors" "io" "sort" "sync" @@ -10,7 +11,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/container" "github.com/docker/docker/errdefs" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) diff --git a/cli/command/container/tty_test.go b/cli/command/container/tty_test.go index c90d9417a7..27daeb8ed9 100644 --- a/cli/command/container/tty_test.go +++ b/cli/command/container/tty_test.go @@ -2,13 +2,14 @@ package container import ( "context" + "fmt" "testing" "time" "github.com/docker/cli/cli/command" "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/container" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -16,7 +17,7 @@ import ( func TestInitTtySizeErrors(t *testing.T) { expectedError := "failed to resize tty, using default size\n" fakeContainerExecResizeFunc := func(id string, options container.ResizeOptions) error { - return errors.Errorf("Error response from daemon: no such exec") + return fmt.Errorf("Error response from daemon: no such exec") } fakeResizeTtyFunc := func(ctx context.Context, cli command.Cli, id string, isExec bool) error { height, width := uint(1024), uint(768) diff --git a/cli/command/container/unpause.go b/cli/command/container/unpause.go index cffd94d4c2..96796aa367 100644 --- a/cli/command/container/unpause.go +++ b/cli/command/container/unpause.go @@ -2,6 +2,7 @@ package container import ( "context" + "errors" "fmt" "strings" @@ -9,7 +10,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" "github.com/docker/docker/api/types/container" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/container/update.go b/cli/command/container/update.go index 275ec5f646..b50140375f 100644 --- a/cli/command/container/update.go +++ b/cli/command/container/update.go @@ -2,6 +2,7 @@ package container import ( "context" + "errors" "fmt" "strings" @@ -10,7 +11,7 @@ import ( "github.com/docker/cli/cli/command/completion" "github.com/docker/cli/opts" containertypes "github.com/docker/docker/api/types/container" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/container/wait.go b/cli/command/container/wait.go index 8eb7d82f80..434e58653e 100644 --- a/cli/command/container/wait.go +++ b/cli/command/container/wait.go @@ -2,13 +2,14 @@ package container import ( "context" + "errors" "fmt" "strings" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/context/create.go b/cli/command/context/create.go index 3f2cefeabc..d91257a17a 100644 --- a/cli/command/context/create.go +++ b/cli/command/context/create.go @@ -5,6 +5,7 @@ package context import ( "bytes" + "errors" "fmt" "github.com/docker/cli/cli" @@ -14,7 +15,7 @@ import ( "github.com/docker/cli/cli/context/docker" "github.com/docker/cli/cli/context/store" "github.com/docker/docker/errdefs" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -91,7 +92,7 @@ func createNewContext(contextStore store.ReaderWriter, o *CreateOptions) error { } dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(contextStore, o.Docker) if err != nil { - return errors.Wrap(err, "unable to create docker endpoint config") + return fmt.Errorf("unable to create docker endpoint config: %w", err) } contextMetadata := store.Metadata{ Endpoints: map[string]any{ @@ -124,9 +125,9 @@ func checkContextNameForCreation(s store.Reader, name string) error { } if _, err := s.GetMetadata(name); !errdefs.IsNotFound(err) { if err != nil { - return errors.Wrap(err, "error while getting existing contexts") + return fmt.Errorf("error while getting existing contexts: %w", err) } - return errors.Errorf("context %q already exists", name) + return fmt.Errorf("context %q already exists", name) } return nil } diff --git a/cli/command/context/options.go b/cli/command/context/options.go index d1cdb1e9c5..7a73aa8298 100644 --- a/cli/command/context/options.go +++ b/cli/command/context/options.go @@ -1,6 +1,7 @@ package context import ( + "errors" "fmt" "strconv" "strings" @@ -9,7 +10,6 @@ import ( "github.com/docker/cli/cli/context/docker" "github.com/docker/cli/cli/context/store" "github.com/docker/docker/client" - "github.com/pkg/errors" ) const ( @@ -100,7 +100,7 @@ func getDockerEndpoint(contextStore store.Reader, config map[string]string) (doc if ep, ok := metadata.Endpoints[docker.DockerEndpoint].(docker.EndpointMeta); ok { return docker.Endpoint{EndpointMeta: ep}, nil } - return docker.Endpoint{}, errors.Errorf("unable to get endpoint from context %q", contextName) + return docker.Endpoint{}, fmt.Errorf("unable to get endpoint from context %q", contextName) } tlsData, err := context.TLSDataFromFiles(config[keyCA], config[keyCert], config[keyKey]) if err != nil { @@ -120,10 +120,10 @@ func getDockerEndpoint(contextStore store.Reader, config map[string]string) (doc // try to resolve a docker client, validating the configuration opts, err := ep.ClientOpts() if err != nil { - return docker.Endpoint{}, errors.Wrap(err, "invalid docker endpoint options") + return docker.Endpoint{}, fmt.Errorf("invalid docker endpoint options: %w", err) } if _, err := client.NewClientWithOpts(opts...); err != nil { - return docker.Endpoint{}, errors.Wrap(err, "unable to apply docker endpoint options") + return docker.Endpoint{}, fmt.Errorf("unable to apply docker endpoint options: %w", err) } return ep, nil } diff --git a/cli/command/context/remove.go b/cli/command/context/remove.go index 9ba405d588..9a85009fe3 100644 --- a/cli/command/context/remove.go +++ b/cli/command/context/remove.go @@ -1,6 +1,7 @@ package context import ( + "errors" "fmt" "os" "strings" @@ -8,7 +9,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/docker/errdefs" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -54,7 +55,7 @@ func RunRemove(dockerCli command.Cli, opts RemoveOptions, names []string) error func doRemove(dockerCli command.Cli, name string, isCurrent, force bool) error { if isCurrent { if !force { - return errors.Errorf("context %q is in use, set -f flag to force remove", name) + return fmt.Errorf("context %q is in use, set -f flag to force remove", name) } // fallback to DOCKER_HOST cfg := dockerCli.ConfigFile() @@ -77,7 +78,7 @@ func checkContextExists(dockerCli command.Cli, name string) error { contextDir := dockerCli.ContextStore().GetStorageInfo(name).MetadataPath _, err := os.Stat(contextDir) if os.IsNotExist(err) { - return errdefs.NotFound(errors.Errorf("context %q does not exist", name)) + return errdefs.NotFound(fmt.Errorf("context %q does not exist", name)) } // Ignore other errors; if relevant, they will produce an error when // performing the actual delete. diff --git a/cli/command/context/update.go b/cli/command/context/update.go index 98eba7d1ec..fb425579da 100644 --- a/cli/command/context/update.go +++ b/cli/command/context/update.go @@ -9,7 +9,7 @@ import ( "github.com/docker/cli/cli/command/formatter/tabwriter" "github.com/docker/cli/cli/context/docker" "github.com/docker/cli/cli/context/store" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -76,7 +76,7 @@ func RunUpdate(dockerCLI command.Cli, o *UpdateOptions) error { if o.Docker != nil { dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(s, o.Docker) if err != nil { - return errors.Wrap(err, "unable to create docker endpoint config") + return fmt.Errorf("unable to create docker endpoint config: %w", err) } c.Endpoints[docker.DockerEndpoint] = dockerEP tlsDataToReset[docker.DockerEndpoint] = dockerTLS diff --git a/cli/command/defaultcontextstore.go b/cli/command/defaultcontextstore.go index 2582257680..50741e7622 100644 --- a/cli/command/defaultcontextstore.go +++ b/cli/command/defaultcontextstore.go @@ -4,11 +4,12 @@ package command import ( + "errors" + "fmt" "github.com/docker/cli/cli/context/docker" "github.com/docker/cli/cli/context/store" cliflags "github.com/docker/cli/cli/flags" "github.com/docker/docker/errdefs" - "github.com/pkg/errors" ) const ( @@ -186,7 +187,7 @@ func (s *ContextStoreWithDefault) GetTLSData(contextName, endpointName, fileName return nil, err } if defaultContext.TLS.Endpoints[endpointName].Files[fileName] == nil { - return nil, errdefs.NotFound(errors.Errorf("TLS data for %s/%s/%s does not exist", DefaultContextName, endpointName, fileName)) + return nil, errdefs.NotFound(fmt.Errorf("TLS data for %s/%s/%s does not exist", DefaultContextName, endpointName, fileName)) } return defaultContext.TLS.Endpoints[endpointName].Files[fileName], nil } diff --git a/cli/command/formatter/formatter.go b/cli/command/formatter/formatter.go index 4f10377255..449b0782ed 100644 --- a/cli/command/formatter/formatter.go +++ b/cli/command/formatter/formatter.go @@ -5,13 +5,13 @@ package formatter import ( "bytes" + "fmt" "io" "strings" "text/template" "github.com/docker/cli/cli/command/formatter/tabwriter" "github.com/docker/cli/templates" - "github.com/pkg/errors" ) // Format keys used to specify certain kinds of output formats @@ -76,7 +76,7 @@ func (c *Context) preFormat() { func (c *Context) parseFormat() (*template.Template, error) { tmpl, err := templates.Parse(c.finalFormat) if err != nil { - return tmpl, errors.Wrap(err, "template parsing error") + return tmpl, fmt.Errorf("template parsing error: %w", err) } return tmpl, err } @@ -97,7 +97,7 @@ func (c *Context) postFormat(tmpl *template.Template, subContext SubContext) { func (c *Context) contextFormat(tmpl *template.Template, subContext SubContext) error { if err := tmpl.Execute(c.buffer, subContext); err != nil { - return errors.Wrap(err, "template parsing error") + return fmt.Errorf("template parsing error: %w", err) } if c.Format.IsTable() && c.header != nil { c.header = subContext.FullHeader() diff --git a/cli/command/formatter/reflect.go b/cli/command/formatter/reflect.go index e2c0b28f53..66c9d6340b 100644 --- a/cli/command/formatter/reflect.go +++ b/cli/command/formatter/reflect.go @@ -5,10 +5,9 @@ package formatter import ( "encoding/json" + "fmt" "reflect" "unicode" - - "github.com/pkg/errors" ) // MarshalJSON marshals x into json @@ -25,14 +24,14 @@ func MarshalJSON(x any) ([]byte, error) { func marshalMap(x any) (map[string]any, error) { val := reflect.ValueOf(x) if val.Kind() != reflect.Ptr { - return nil, errors.Errorf("expected a pointer to a struct, got %v", val.Kind()) + return nil, fmt.Errorf("expected a pointer to a struct, got %v", val.Kind()) } if val.IsNil() { - return nil, errors.Errorf("expected a pointer to a struct, got nil pointer") + return nil, fmt.Errorf("expected a pointer to a struct, got nil pointer") } valElem := val.Elem() if valElem.Kind() != reflect.Struct { - return nil, errors.Errorf("expected a pointer to a struct, got a pointer to %v", valElem.Kind()) + return nil, fmt.Errorf("expected a pointer to a struct, got a pointer to %v", valElem.Kind()) } typ := val.Type() m := make(map[string]any) @@ -54,7 +53,7 @@ var unmarshallableNames = map[string]struct{}{"FullHeader": {}} // It returns ("", nil, nil) for valid but non-marshallable parameter. (e.g. "unexportedFunc()") func marshalForMethod(typ reflect.Method, val reflect.Value) (string, any, error) { if val.Kind() != reflect.Func { - return "", nil, errors.Errorf("expected func, got %v", val.Kind()) + return "", nil, fmt.Errorf("expected func, got %v", val.Kind()) } name, numIn, numOut := typ.Name, val.Type().NumIn(), val.Type().NumOut() _, blackListed := unmarshallableNames[name] diff --git a/cli/command/idresolver/idresolver.go b/cli/command/idresolver/idresolver.go index 802ff46fe1..7e12aa1711 100644 --- a/cli/command/idresolver/idresolver.go +++ b/cli/command/idresolver/idresolver.go @@ -5,11 +5,11 @@ package idresolver import ( "context" + "fmt" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" - "github.com/pkg/errors" ) // IDResolver provides ID to Name resolution. @@ -51,7 +51,7 @@ func (r *IDResolver) get(ctx context.Context, t any, id string) (string, error) } return service.Spec.Annotations.Name, nil default: - return "", errors.Errorf("unsupported type") + return "", fmt.Errorf("unsupported type") } } diff --git a/cli/command/idresolver/idresolver_test.go b/cli/command/idresolver/idresolver_test.go index 1b8810c7ae..3ef715d7e2 100644 --- a/cli/command/idresolver/idresolver_test.go +++ b/cli/command/idresolver/idresolver_test.go @@ -2,11 +2,12 @@ package idresolver import ( "context" + "fmt" "testing" "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -14,7 +15,7 @@ import ( func TestResolveError(t *testing.T) { cli := &fakeClient{ nodeInspectFunc: func(nodeID string) (swarm.Node, []byte, error) { - return swarm.Node{}, []byte{}, errors.Errorf("error inspecting node") + return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting node") }, } @@ -75,7 +76,7 @@ func TestResolveNode(t *testing.T) { { nodeID: "nodeID", nodeInspectFunc: func(string) (swarm.Node, []byte, error) { - return swarm.Node{}, []byte{}, errors.Errorf("error inspecting node") + return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting node") }, expectedID: "nodeID", }, @@ -117,7 +118,7 @@ func TestResolveService(t *testing.T) { { serviceID: "serviceID", serviceInspectFunc: func(string) (swarm.Service, []byte, error) { - return swarm.Service{}, []byte{}, errors.Errorf("error inspecting service") + return swarm.Service{}, []byte{}, fmt.Errorf("error inspecting service") }, expectedID: "serviceID", }, diff --git a/cli/command/image/build.go b/cli/command/image/build.go index 4a258646dc..bd7133f5a8 100644 --- a/cli/command/image/build.go +++ b/cli/command/image/build.go @@ -6,6 +6,7 @@ import ( "bytes" "context" "encoding/json" + "errors" "fmt" "io" "os" @@ -31,7 +32,7 @@ import ( "github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/progress" "github.com/docker/docker/pkg/streamformatter" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -212,7 +213,7 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions) if options.imageIDFile != "" { // Avoid leaving a stale file if we eventually fail if err := os.Remove(options.imageIDFile); err != nil && !os.IsNotExist(err) { - return errors.Wrap(err, "Removing image ID file") + return fmt.Errorf("Removing image ID file: %w", err) } } @@ -226,7 +227,7 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions) // Dockerfile is outside of build-context; read the Dockerfile and pass it as dockerfileCtx dockerfileCtx, err = os.Open(options.dockerfileName) if err != nil { - return errors.Errorf("unable to open Dockerfile: %v", err) + return fmt.Errorf("unable to open Dockerfile: %v", err) } defer dockerfileCtx.Close() } @@ -235,14 +236,14 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions) case urlutil.IsURL(specifiedContext): buildCtx, relDockerfile, err = build.GetContextFromURL(progBuff, specifiedContext, options.dockerfileName) default: - return errors.Errorf("unable to prepare context: path %q not found", specifiedContext) + return fmt.Errorf("unable to prepare context: path %q not found", specifiedContext) } if err != nil { if options.quiet && urlutil.IsURL(specifiedContext) { fmt.Fprintln(dockerCli.Err(), progBuff) } - return errors.Errorf("unable to prepare context: %s", err) + return fmt.Errorf("unable to prepare context: %s", err) } if tempDir != "" { @@ -258,7 +259,7 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions) } if err := build.ValidateContextDirectory(contextDir, excludes); err != nil { - return errors.Wrap(err, "error checking context") + return fmt.Errorf("error checking context: %w", err) } // And canonicalize dockerfile name to a platform-independent one @@ -395,7 +396,7 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions) if options.imageIDFile != "" { if imageID == "" { - return errors.Errorf("Server did not provide an image ID. Cannot write %s", options.imageIDFile) + return fmt.Errorf("Server did not provide an image ID. Cannot write %s", options.imageIDFile) } if err := os.WriteFile(options.imageIDFile, []byte(imageID), 0o666); err != nil { return err diff --git a/cli/command/image/build/context.go b/cli/command/image/build/context.go index 2b8fed3be5..8c91df0308 100644 --- a/cli/command/image/build/context.go +++ b/cli/command/image/build/context.go @@ -4,6 +4,7 @@ import ( "archive/tar" "bufio" "bytes" + "errors" "fmt" "io" "net/http" @@ -22,7 +23,6 @@ import ( "github.com/docker/docker/pkg/streamformatter" "github.com/docker/docker/pkg/stringid" "github.com/moby/patternmatcher" - "github.com/pkg/errors" ) const ( @@ -49,10 +49,10 @@ func ValidateContextDirectory(srcPath string, excludes []string) error { return filepath.Walk(contextRoot, func(filePath string, f os.FileInfo, err error) error { if err != nil { if os.IsPermission(err) { - return errors.Errorf("can't stat '%s'", filePath) + return fmt.Errorf("can't stat '%s'", filePath) } if os.IsNotExist(err) { - return errors.Errorf("file ('%s') not found or excluded by .dockerignore", filePath) + return fmt.Errorf("file ('%s') not found or excluded by .dockerignore", filePath) } return err } @@ -78,7 +78,7 @@ func ValidateContextDirectory(srcPath string, excludes []string) error { if !f.IsDir() { currentFile, err := os.Open(filePath) if err != nil && os.IsPermission(err) { - return errors.Errorf("no permission to read from '%s'", filePath) + return fmt.Errorf("no permission to read from '%s'", filePath) } currentFile.Close() } @@ -105,7 +105,7 @@ func DetectArchiveReader(input io.ReadCloser) (rc io.ReadCloser, isArchive bool, magic, err := buf.Peek(archiveHeaderSize * 2) if err != nil && err != io.EOF { - return nil, false, errors.Errorf("failed to peek context header from STDIN: %v", err) + return nil, false, fmt.Errorf("failed to peek context header from STDIN: %v", err) } return ioutils.NewReadCloserWrapper(buf, func() error { return input.Close() }), IsArchive(magic), nil @@ -118,7 +118,7 @@ func WriteTempDockerfile(rc io.ReadCloser) (dockerfileDir string, err error) { // err is a named return value, due to the defer call below. dockerfileDir, err = os.MkdirTemp("", "docker-build-tempdockerfile-") if err != nil { - return "", errors.Errorf("unable to create temporary context directory: %v", err) + return "", fmt.Errorf("unable to create temporary context directory: %v", err) } defer func() { if err != nil { @@ -195,11 +195,11 @@ func IsArchive(header []byte) bool { // success. func GetContextFromGitURL(gitURL, dockerfileName string) (string, string, error) { if _, err := exec.LookPath("git"); err != nil { - return "", "", errors.Wrapf(err, "unable to find 'git'") + return "", "", fmt.Errorf("unable to find 'git': %w", err) } absContextDir, err := git.Clone(gitURL) if err != nil { - return "", "", errors.Wrapf(err, "unable to 'git clone' to temporary context directory") + return "", "", fmt.Errorf("unable to 'git clone' to temporary context directory: %w", err) } absContextDir, err = ResolveAndValidateContextPath(absContextDir) @@ -208,7 +208,7 @@ func GetContextFromGitURL(gitURL, dockerfileName string) (string, string, error) } relDockerfile, err := getDockerfileRelPath(absContextDir, dockerfileName) if err == nil && strings.HasPrefix(relDockerfile, ".."+string(filepath.Separator)) { - return "", "", errors.Errorf("the Dockerfile (%s) must be within the build context", dockerfileName) + return "", "", fmt.Errorf("the Dockerfile (%s) must be within the build context", dockerfileName) } return absContextDir, relDockerfile, err @@ -221,7 +221,7 @@ func GetContextFromGitURL(gitURL, dockerfileName string) (string, string, error) func GetContextFromURL(out io.Writer, remoteURL, dockerfileName string) (io.ReadCloser, string, error) { response, err := getWithStatusError(remoteURL) if err != nil { - return nil, "", errors.Errorf("unable to download remote context %s: %v", remoteURL, err) + return nil, "", fmt.Errorf("unable to download remote context %s: %v", remoteURL, err) } progressOutput := streamformatter.NewProgressOutput(out) @@ -245,9 +245,9 @@ func getWithStatusError(url string) (resp *http.Response, err error) { body, err := io.ReadAll(resp.Body) resp.Body.Close() if err != nil { - return nil, errors.Wrapf(err, "%s: error reading body", msg) + return nil, fmt.Errorf("%s: error reading body: %w", msg, err) } - return nil, errors.Errorf("%s: %s", msg, bytes.TrimSpace(body)) + return nil, fmt.Errorf("%s: %s", msg, bytes.TrimSpace(body)) } // GetContextFromLocalDir uses the given local directory as context for a @@ -265,7 +265,7 @@ func GetContextFromLocalDir(localDir, dockerfileName string) (string, string, er // current directory and not the context directory. if dockerfileName != "" && dockerfileName != "-" { if dockerfileName, err = filepath.Abs(dockerfileName); err != nil { - return "", "", errors.Errorf("unable to get absolute path to Dockerfile: %v", err) + return "", "", fmt.Errorf("unable to get absolute path to Dockerfile: %v", err) } } @@ -278,7 +278,7 @@ func GetContextFromLocalDir(localDir, dockerfileName string) (string, string, er func ResolveAndValidateContextPath(givenContextDir string) (string, error) { absContextDir, err := filepath.Abs(givenContextDir) if err != nil { - return "", errors.Errorf("unable to get absolute context directory of given context directory %q: %v", givenContextDir, err) + return "", fmt.Errorf("unable to get absolute context directory of given context directory %q: %v", givenContextDir, err) } // The context dir might be a symbolic link, so follow it to the actual @@ -291,17 +291,17 @@ func ResolveAndValidateContextPath(givenContextDir string) (string, error) { if !isUNC(absContextDir) { absContextDir, err = filepath.EvalSymlinks(absContextDir) if err != nil { - return "", errors.Errorf("unable to evaluate symlinks in context path: %v", err) + return "", fmt.Errorf("unable to evaluate symlinks in context path: %v", err) } } stat, err := os.Lstat(absContextDir) if err != nil { - return "", errors.Errorf("unable to stat context directory %q: %v", absContextDir, err) + return "", fmt.Errorf("unable to stat context directory %q: %v", absContextDir, err) } if !stat.IsDir() { - return "", errors.Errorf("context must be a directory: %s", absContextDir) + return "", fmt.Errorf("context must be a directory: %s", absContextDir) } return absContextDir, err } @@ -346,20 +346,20 @@ func getDockerfileRelPath(absContextDir, givenDockerfile string) (string, error) if !isUNC(absDockerfile) { absDockerfile, err = filepath.EvalSymlinks(absDockerfile) if err != nil { - return "", errors.Errorf("unable to evaluate symlinks in Dockerfile path: %v", err) + return "", fmt.Errorf("unable to evaluate symlinks in Dockerfile path: %v", err) } } if _, err := os.Lstat(absDockerfile); err != nil { if os.IsNotExist(err) { - return "", errors.Errorf("Cannot locate Dockerfile: %q", absDockerfile) + return "", fmt.Errorf("Cannot locate Dockerfile: %q", absDockerfile) } - return "", errors.Errorf("unable to stat Dockerfile: %v", err) + return "", fmt.Errorf("unable to stat Dockerfile: %v", err) } relDockerfile, err := filepath.Rel(absContextDir, absDockerfile) if err != nil { - return "", errors.Errorf("unable to get relative Dockerfile path: %v", err) + return "", fmt.Errorf("unable to get relative Dockerfile path: %v", err) } return relDockerfile, nil @@ -435,7 +435,7 @@ func Compress(buildCtx io.ReadCloser) (io.ReadCloser, error) { defer buildCtx.Close() if _, err := pools.Copy(compressWriter, buildCtx); err != nil { - pipeWriter.CloseWithError(errors.Wrap(err, "failed to compress context")) + pipeWriter.CloseWithError(fmt.Errorf("failed to compress context: %w", err)) compressWriter.Close() return } diff --git a/cli/command/image/history_test.go b/cli/command/image/history_test.go index b4c519de29..842f337d49 100644 --- a/cli/command/image/history_test.go +++ b/cli/command/image/history_test.go @@ -8,7 +8,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/image" - "github.com/pkg/errors" + "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -30,7 +30,7 @@ func TestNewHistoryCommandErrors(t *testing.T) { args: []string{"image:tag"}, expectedError: "something went wrong", imageHistoryFunc: func(img string, options image.HistoryOptions) ([]image.HistoryResponseItem, error) { - return []image.HistoryResponseItem{{}}, errors.Errorf("something went wrong") + return []image.HistoryResponseItem{{}}, fmt.Errorf("something went wrong") }, }, } diff --git a/cli/command/image/import_test.go b/cli/command/image/import_test.go index 196171ed31..a1e1f372ef 100644 --- a/cli/command/image/import_test.go +++ b/cli/command/image/import_test.go @@ -1,13 +1,14 @@ package image import ( + "fmt" "io" "strings" "testing" "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/image" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -29,7 +30,7 @@ func TestNewImportCommandErrors(t *testing.T) { args: []string{"testdata/import-command-success.input.txt"}, expectedError: "something went wrong", imageImportFunc: func(source image.ImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error) { - return nil, errors.Errorf("something went wrong") + return nil, fmt.Errorf("something went wrong") }, }, } diff --git a/cli/command/image/list_test.go b/cli/command/image/list_test.go index 8ccec6ab56..3589948e31 100644 --- a/cli/command/image/list_test.go +++ b/cli/command/image/list_test.go @@ -8,7 +8,7 @@ import ( "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/image" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -30,7 +30,7 @@ func TestNewImagesCommandErrors(t *testing.T) { name: "failed-list", expectedError: "something went wrong", imageListFunc: func(options image.ListOptions) ([]image.Summary, error) { - return []image.Summary{}, errors.Errorf("something went wrong") + return []image.Summary{}, fmt.Errorf("something went wrong") }, }, } diff --git a/cli/command/image/load.go b/cli/command/image/load.go index 190e9302a3..7b4fe43342 100644 --- a/cli/command/image/load.go +++ b/cli/command/image/load.go @@ -2,6 +2,7 @@ package image import ( "context" + "fmt" "io" "github.com/docker/cli/cli" @@ -10,7 +11,7 @@ import ( "github.com/docker/docker/api/types/image" "github.com/docker/docker/pkg/jsonmessage" "github.com/moby/sys/sequential" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -60,7 +61,7 @@ func runLoad(ctx context.Context, dockerCli command.Cli, opts loadOptions) error // To avoid getting stuck, verify that a tar file is given either in // the input flag or through stdin and if not display an error message and exit. if opts.input == "" && dockerCli.In().IsTerminal() { - return errors.Errorf("requested load from stdin, but stdin is empty") + return fmt.Errorf("requested load from stdin, but stdin is empty") } var loadOpts image.LoadOptions diff --git a/cli/command/image/load_test.go b/cli/command/image/load_test.go index 30edd87789..22845316fd 100644 --- a/cli/command/image/load_test.go +++ b/cli/command/image/load_test.go @@ -8,7 +8,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/image" - "github.com/pkg/errors" + "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -37,7 +37,7 @@ func TestNewLoadCommandErrors(t *testing.T) { args: []string{}, expectedError: "something went wrong", imageLoadFunc: func(input io.Reader, options image.LoadOptions) (image.LoadResponse, error) { - return image.LoadResponse{}, errors.Errorf("something went wrong") + return image.LoadResponse{}, fmt.Errorf("something went wrong") }, }, } diff --git a/cli/command/image/prune.go b/cli/command/image/prune.go index 7bdb24d8c5..8cdf9e2b32 100644 --- a/cli/command/image/prune.go +++ b/cli/command/image/prune.go @@ -2,6 +2,7 @@ package image import ( "context" + "errors" "fmt" "strconv" "strings" @@ -12,7 +13,7 @@ import ( "github.com/docker/cli/opts" "github.com/docker/docker/errdefs" units "github.com/docker/go-units" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/image/prune_test.go b/cli/command/image/prune_test.go index 710c1cf748..c20be03bc5 100644 --- a/cli/command/image/prune_test.go +++ b/cli/command/image/prune_test.go @@ -2,6 +2,7 @@ package image import ( "context" + "errors" "fmt" "io" "strings" @@ -11,7 +12,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/image" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -34,7 +35,7 @@ func TestNewPruneCommandErrors(t *testing.T) { args: []string{"--force"}, expectedError: "something went wrong", imagesPruneFunc: func(pruneFilter filters.Args) (image.PruneReport, error) { - return image.PruneReport{}, errors.Errorf("something went wrong") + return image.PruneReport{}, fmt.Errorf("something went wrong") }, }, } diff --git a/cli/command/image/pull.go b/cli/command/image/pull.go index 93388253f7..236939f6ac 100644 --- a/cli/command/image/pull.go +++ b/cli/command/image/pull.go @@ -2,6 +2,7 @@ package image import ( "context" + "errors" "fmt" "strings" @@ -10,7 +11,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" "github.com/docker/cli/cli/trust" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/image/push.go b/cli/command/image/push.go index 92ef1a159a..7c206a169d 100644 --- a/cli/command/image/push.go +++ b/cli/command/image/push.go @@ -6,6 +6,7 @@ package image import ( "context" "encoding/json" + "errors" "fmt" "io" "strings" @@ -23,7 +24,7 @@ import ( "github.com/docker/docker/registry" "github.com/morikuni/aec" ocispec "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/image/push_test.go b/cli/command/image/push_test.go index 3f9d2fe59f..b98368723c 100644 --- a/cli/command/image/push_test.go +++ b/cli/command/image/push_test.go @@ -1,13 +1,14 @@ package image import ( + "fmt" "io" "strings" "testing" "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/image" - "github.com/pkg/errors" + "gotest.tools/v3/assert" ) @@ -33,7 +34,7 @@ func TestNewPushCommandErrors(t *testing.T) { args: []string{"image:repo"}, expectedError: "Failed to push", imagePushFunc: func(ref string, options image.PushOptions) (io.ReadCloser, error) { - return io.NopCloser(strings.NewReader("")), errors.Errorf("Failed to push") + return io.NopCloser(strings.NewReader("")), fmt.Errorf("Failed to push") }, }, } diff --git a/cli/command/image/remove.go b/cli/command/image/remove.go index 3fb0af5c03..1e7e781250 100644 --- a/cli/command/image/remove.go +++ b/cli/command/image/remove.go @@ -2,6 +2,7 @@ package image import ( "context" + "errors" "fmt" "strings" @@ -10,7 +11,7 @@ import ( "github.com/docker/cli/cli/command/completion" "github.com/docker/docker/api/types/image" "github.com/docker/docker/errdefs" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/image/remove_test.go b/cli/command/image/remove_test.go index 0340a65b94..20c8d958cb 100644 --- a/cli/command/image/remove_test.go +++ b/cli/command/image/remove_test.go @@ -7,7 +7,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/image" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -47,7 +47,7 @@ func TestNewRemoveCommandErrors(t *testing.T) { expectedError: "error removing image", imageRemoveFunc: func(img string, options image.RemoveOptions) ([]image.DeleteResponse, error) { assert.Check(t, is.Equal("image1", img)) - return []image.DeleteResponse{}, errors.Errorf("error removing image") + return []image.DeleteResponse{}, fmt.Errorf("error removing image") }, }, { @@ -57,7 +57,7 @@ func TestNewRemoveCommandErrors(t *testing.T) { imageRemoveFunc: func(img string, options image.RemoveOptions) ([]image.DeleteResponse, error) { assert.Check(t, !options.Force) assert.Check(t, options.PruneChildren) - return []image.DeleteResponse{}, errors.Errorf("error removing image") + return []image.DeleteResponse{}, fmt.Errorf("error removing image") }, }, } diff --git a/cli/command/image/save.go b/cli/command/image/save.go index c5a32859b8..2620ddbff0 100644 --- a/cli/command/image/save.go +++ b/cli/command/image/save.go @@ -2,13 +2,15 @@ package image import ( "context" + "errors" + "fmt" "io" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" "github.com/docker/docker/api/types/image" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -49,7 +51,7 @@ func RunSave(ctx context.Context, dockerCli command.Cli, opts saveOptions) error } if err := command.ValidateOutputPath(opts.output); err != nil { - return errors.Wrap(err, "failed to save image") + return fmt.Errorf("failed to save image: %w", err) } responseBody, err := dockerCli.Client().ImageSave(ctx, opts.images, image.SaveOptions{}) diff --git a/cli/command/image/save_test.go b/cli/command/image/save_test.go index 8a399bdfa6..c3d78e8a61 100644 --- a/cli/command/image/save_test.go +++ b/cli/command/image/save_test.go @@ -1,6 +1,7 @@ package image import ( + "fmt" "io" "os" "strings" @@ -8,7 +9,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/image" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -38,7 +39,7 @@ func TestNewSaveCommandErrors(t *testing.T) { isTerminal: false, expectedError: "error saving image", imageSaveFunc: func(images []string, options image.SaveOptions) (io.ReadCloser, error) { - return io.NopCloser(strings.NewReader("")), errors.Errorf("error saving image") + return io.NopCloser(strings.NewReader("")), fmt.Errorf("error saving image") }, }, { diff --git a/cli/command/image/trust.go b/cli/command/image/trust.go index 6bb21fa556..ba2e7f5064 100644 --- a/cli/command/image/trust.go +++ b/cli/command/image/trust.go @@ -4,6 +4,7 @@ import ( "context" "encoding/hex" "encoding/json" + "errors" "fmt" "io" "sort" @@ -18,7 +19,7 @@ import ( "github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/registry" "github.com/opencontainers/go-digest" - "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/theupdateframework/notary/client" "github.com/theupdateframework/notary/tuf/data" @@ -96,18 +97,18 @@ func PushTrustedReference(ioStreams command.Streams, repoInfo *registry.Reposito } if cnt > 1 { - return errors.Errorf("internal error: only one call to handleTarget expected") + return fmt.Errorf("internal error: only one call to handleTarget expected") } if target == nil { - return errors.Errorf("no targets found, provide a specific tag in order to sign it") + return fmt.Errorf("no targets found, provide a specific tag in order to sign it") } fmt.Fprintln(ioStreams.Out(), "Signing and pushing trust metadata") repo, err := trust.GetNotaryRepository(ioStreams.In(), ioStreams.Out(), command.UserAgent(), repoInfo, &authConfig, "push", "pull") if err != nil { - return errors.Wrap(err, "error establishing connection to trust repository") + return fmt.Errorf("error establishing connection to trust repository: %w", err) } // get the latest repository metadata so we can figure out which roles to sign @@ -147,7 +148,7 @@ func PushTrustedReference(ioStreams command.Streams, repoInfo *registry.Reposito } if err != nil { - err = errors.Wrapf(err, "failed to sign %s:%s", repoInfo.Name.Name(), tag) + err = fmt.Errorf("failed to sign %s:%s: %w", repoInfo.Name.Name(), tag, err) return trust.NotaryError(repoInfo.Name.Name(), err) } @@ -215,7 +216,7 @@ func trustedPull(ctx context.Context, cli command.Cli, imgRefAndAuth trust.Image func getTrustedPullTargets(cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth) ([]target, error) { notaryRepo, err := cli.NotaryClient(imgRefAndAuth, trust.ActionsPullOnly) if err != nil { - return nil, errors.Wrap(err, "error establishing connection to trust repository") + return nil, fmt.Errorf("error establishing connection to trust repository: %w", err) } ref := imgRefAndAuth.Reference() @@ -241,7 +242,7 @@ func getTrustedPullTargets(cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth) refs = append(refs, t) } if len(refs) == 0 { - return nil, trust.NotaryError(ref.Name(), errors.Errorf("No trusted tags for %s", ref.Name())) + return nil, trust.NotaryError(ref.Name(), fmt.Errorf("No trusted tags for %s", ref.Name())) } return refs, nil } @@ -253,7 +254,7 @@ func getTrustedPullTargets(cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth) // Only get the tag if it's in the top level targets role or the releases delegation role // ignore it if it's in any other delegation roles if t.Role != trust.ReleasesRole && t.Role != data.CanonicalTargetsRole { - return nil, trust.NotaryError(ref.Name(), errors.Errorf("No trust data for %s", tagged.Tag())) + return nil, trust.NotaryError(ref.Name(), fmt.Errorf("No trust data for %s", tagged.Tag())) } logrus.Debugf("retrieving target for %s role", t.Role) @@ -295,7 +296,7 @@ func TrustedReference(ctx context.Context, cli command.Cli, ref reference.NamedT notaryRepo, err := cli.NotaryClient(imgRefAndAuth, []string{"pull"}) if err != nil { - return nil, errors.Wrap(err, "error establishing connection to trust repository") + return nil, fmt.Errorf("error establishing connection to trust repository: %w", err) } t, err := notaryRepo.GetTargetByName(ref.Tag(), trust.ReleasesRole, data.CanonicalTargetsRole) diff --git a/cli/command/inspect/inspector.go b/cli/command/inspect/inspector.go index d618e9214b..49ec239ec5 100644 --- a/cli/command/inspect/inspector.go +++ b/cli/command/inspect/inspector.go @@ -6,13 +6,14 @@ package inspect import ( "bytes" "encoding/json" + "fmt" "io" "strings" "text/template" "github.com/docker/cli/cli" "github.com/docker/cli/templates" - "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) @@ -53,7 +54,7 @@ func NewTemplateInspectorFromString(out io.Writer, tmplStr string) (Inspector, e tmpl, err := templates.Parse(tmplStr) if err != nil { - return nil, errors.Errorf("template parsing error: %s", err) + return nil, fmt.Errorf("template parsing error: %s", err) } return NewTemplateInspector(out, tmpl), nil } @@ -103,7 +104,7 @@ func (i *TemplateInspector) Inspect(typedElement any, rawElement []byte) error { buffer := new(bytes.Buffer) if err := i.tmpl.Execute(buffer, typedElement); err != nil { if rawElement == nil { - return errors.Errorf("template parsing error: %v", err) + return fmt.Errorf("template parsing error: %v", err) } return i.tryRawInspectFallback(rawElement) } @@ -122,12 +123,12 @@ func (i *TemplateInspector) tryRawInspectFallback(rawElement []byte) error { dec.UseNumber() if rawErr := dec.Decode(&raw); rawErr != nil { - return errors.Errorf("unable to read inspect data: %v", rawErr) + return fmt.Errorf("unable to read inspect data: %v", rawErr) } tmplMissingKey := i.tmpl.Option("missingkey=error") if rawErr := tmplMissingKey.Execute(buffer, raw); rawErr != nil { - return errors.Errorf("template parsing error: %v", rawErr) + return fmt.Errorf("template parsing error: %v", rawErr) } i.buffer.Write(buffer.Bytes()) diff --git a/cli/command/manifest/annotate.go b/cli/command/manifest/annotate.go index c12b69d823..916900cb2c 100644 --- a/cli/command/manifest/annotate.go +++ b/cli/command/manifest/annotate.go @@ -7,7 +7,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/manifest/store" ocispec "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -50,11 +50,11 @@ func newAnnotateCommand(dockerCli command.Cli) *cobra.Command { func runManifestAnnotate(dockerCli command.Cli, opts annotateOptions) error { targetRef, err := normalizeReference(opts.target) if err != nil { - return errors.Wrapf(err, "annotate: error parsing name for manifest list %s", opts.target) + return fmt.Errorf("annotate: error parsing name for manifest list %s: %w", opts.target, err) } imgRef, err := normalizeReference(opts.image) if err != nil { - return errors.Wrapf(err, "annotate: error parsing name for manifest %s", opts.image) + return fmt.Errorf("annotate: error parsing name for manifest %s: %w", opts.image, err) } manifestStore := dockerCli.ManifestStore() @@ -87,7 +87,7 @@ func runManifestAnnotate(dockerCli command.Cli, opts annotateOptions) error { } if !isValidOSArch(imageManifest.Descriptor.Platform.OS, imageManifest.Descriptor.Platform.Architecture) { - return errors.Errorf("manifest entry for image has unsupported os/arch combination: %s/%s", opts.os, opts.arch) + return fmt.Errorf("manifest entry for image has unsupported os/arch combination: %s/%s", opts.os, opts.arch) } return manifestStore.Save(targetRef, imgRef, imageManifest) } diff --git a/cli/command/manifest/create_list.go b/cli/command/manifest/create_list.go index ac78b14f62..b567e75143 100644 --- a/cli/command/manifest/create_list.go +++ b/cli/command/manifest/create_list.go @@ -8,7 +8,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/manifest/store" "github.com/docker/docker/registry" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -39,12 +39,12 @@ func createManifestList(ctx context.Context, dockerCli command.Cli, args []strin newRef := args[0] targetRef, err := normalizeReference(newRef) if err != nil { - return errors.Wrapf(err, "error parsing name for manifest list %s", newRef) + return fmt.Errorf("error parsing name for manifest list %s: %w", newRef, err) } _, err = registry.ParseRepositoryInfo(targetRef) if err != nil { - return errors.Wrapf(err, "error parsing repository name for manifest list %s", newRef) + return fmt.Errorf("error parsing repository name for manifest list %s: %w", newRef, err) } manifestStore := dockerCli.ManifestStore() @@ -55,7 +55,7 @@ func createManifestList(ctx context.Context, dockerCli command.Cli, args []strin case err != nil: return err case !opts.amend: - return errors.Errorf("refusing to amend an existing manifest list with no --amend flag") + return fmt.Errorf("refusing to amend an existing manifest list with no --amend flag") } // Now create the local manifest list transaction by looking up the manifest schemas diff --git a/cli/command/manifest/create_test.go b/cli/command/manifest/create_test.go index 0b1296e805..9c991e7d00 100644 --- a/cli/command/manifest/create_test.go +++ b/cli/command/manifest/create_test.go @@ -2,6 +2,7 @@ package manifest import ( "context" + "fmt" "io" "testing" @@ -9,7 +10,7 @@ import ( "github.com/docker/cli/cli/manifest/store" manifesttypes "github.com/docker/cli/cli/manifest/types" "github.com/docker/cli/internal/test" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -104,10 +105,10 @@ func TestManifestCreateNoManifest(t *testing.T) { cli.SetManifestStore(manifestStore) cli.SetRegistryClient(&fakeRegistryClient{ getManifestFunc: func(_ context.Context, ref reference.Named) (manifesttypes.ImageManifest, error) { - return manifesttypes.ImageManifest{}, errors.Errorf("No such image: %v", ref) + return manifesttypes.ImageManifest{}, fmt.Errorf("No such image: %v", ref) }, getManifestListFunc: func(ctx context.Context, ref reference.Named) ([]manifesttypes.ImageManifest, error) { - return nil, errors.Errorf("No such manifest: %s", ref) + return nil, fmt.Errorf("No such manifest: %s", ref) }, }) diff --git a/cli/command/manifest/inspect.go b/cli/command/manifest/inspect.go index 75acb8b604..0669f2336c 100644 --- a/cli/command/manifest/inspect.go +++ b/cli/command/manifest/inspect.go @@ -12,7 +12,7 @@ import ( "github.com/docker/cli/cli/manifest/types" "github.com/docker/distribution/manifest/manifestlist" "github.com/docker/docker/registry" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -123,7 +123,7 @@ func printManifestList(dockerCli command.Cli, namedRef reference.Named, list []t for _, img := range list { mfd, err := buildManifestDescriptor(targetRepo, img) if err != nil { - return errors.Wrap(err, "failed to assemble ManifestDescriptor") + return fmt.Errorf("failed to assemble ManifestDescriptor: %w", err) } manifests = append(manifests, mfd) } diff --git a/cli/command/manifest/inspect_test.go b/cli/command/manifest/inspect_test.go index 0009b41770..875adfb4a8 100644 --- a/cli/command/manifest/inspect_test.go +++ b/cli/command/manifest/inspect_test.go @@ -2,6 +2,8 @@ package manifest import ( "context" + "errors" + "fmt" "io" "testing" @@ -13,7 +15,7 @@ import ( "github.com/docker/distribution/manifest/schema2" "github.com/opencontainers/go-digest" ocispec "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -86,7 +88,7 @@ func TestInspectCommandNotFound(t *testing.T) { return types.ImageManifest{}, errors.New("missing") }, getManifestListFunc: func(ctx context.Context, ref reference.Named) ([]types.ImageManifest, error) { - return nil, errors.Errorf("No such manifest: %s", ref) + return nil, fmt.Errorf("No such manifest: %s", ref) }, }) diff --git a/cli/command/manifest/push.go b/cli/command/manifest/push.go index 29fcffe30f..c00c9b1997 100644 --- a/cli/command/manifest/push.go +++ b/cli/command/manifest/push.go @@ -16,7 +16,7 @@ import ( "github.com/docker/distribution/manifest/ocischema" "github.com/docker/distribution/manifest/schema2" "github.com/docker/docker/registry" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -74,7 +74,7 @@ func runPush(ctx context.Context, dockerCli command.Cli, opts pushOpts) error { return err } if len(manifests) == 0 { - return errors.Errorf("%s not found", targetRef) + return fmt.Errorf("%s not found", targetRef) } req, err := buildPushRequest(manifests, targetRef, opts.insecure) @@ -144,7 +144,7 @@ func buildManifestList(manifests []types.ImageManifest, targetRef reference.Name if imageManifest.Descriptor.Platform == nil || imageManifest.Descriptor.Platform.Architecture == "" || imageManifest.Descriptor.Platform.OS == "" { - return nil, errors.Errorf( + return nil, fmt.Errorf( "manifest %s must have an OS and Architecture to be pushed to a registry", imageManifest.Ref) } descriptor, err := buildManifestDescriptor(targetRepoInfo, imageManifest) @@ -166,7 +166,7 @@ func buildManifestDescriptor(targetRepo *registry.RepositoryInfo, imageManifest manifestRepoHostname := reference.Domain(repoInfo.Name) targetRepoHostname := reference.Domain(targetRepo.Name) if manifestRepoHostname != targetRepoHostname { - return manifestlist.ManifestDescriptor{}, errors.Errorf("cannot use source images from a different registry than the target image: %s != %s", manifestRepoHostname, targetRepoHostname) + return manifestlist.ManifestDescriptor{}, fmt.Errorf("cannot use source images from a different registry than the target image: %s != %s", manifestRepoHostname, targetRepoHostname) } manifest := manifestlist.ManifestDescriptor{ @@ -183,8 +183,9 @@ func buildManifestDescriptor(targetRepo *registry.RepositoryInfo, imageManifest } if err = manifest.Descriptor.Digest.Validate(); err != nil { - return manifestlist.ManifestDescriptor{}, errors.Wrapf(err, - "digest parse of image %q failed", imageManifest.Ref) + return manifestlist.ManifestDescriptor{}, fmt.Errorf( + "digest parse of image %q failed: %w", imageManifest.Ref, err, + ) } return manifest, nil @@ -236,7 +237,7 @@ func buildPutManifestRequest(imageManifest types.ImageManifest, targetRef refere dig := imageManifest.Descriptor.Digest if dig2 := dig.Algorithm().FromBytes(dt); dig != dig2 { - return mountRequest{}, errors.Errorf("internal digest mismatch for %s: expected %s, got %s", imageManifest.Ref, dig, dig2) + return mountRequest{}, fmt.Errorf("internal digest mismatch for %s: expected %s, got %s", imageManifest.Ref, dig, dig2) } var manifest schema2.DeserializedManifest @@ -255,7 +256,7 @@ func buildPutManifestRequest(imageManifest types.ImageManifest, targetRef refere dig := imageManifest.Descriptor.Digest if dig2 := dig.Algorithm().FromBytes(dt); dig != dig2 { - return mountRequest{}, errors.Errorf("internal digest mismatch for %s: expected %s, got %s", imageManifest.Ref, dig, dig2) + return mountRequest{}, fmt.Errorf("internal digest mismatch for %s: expected %s, got %s", imageManifest.Ref, dig, dig2) } var manifest ocischema.DeserializedManifest diff --git a/cli/command/manifest/push_test.go b/cli/command/manifest/push_test.go index a10d5b24db..503006cd3e 100644 --- a/cli/command/manifest/push_test.go +++ b/cli/command/manifest/push_test.go @@ -2,6 +2,8 @@ package manifest import ( "context" + "errors" + "fmt" "io" "testing" @@ -9,7 +11,7 @@ import ( "github.com/docker/cli/cli/manifest/store" manifesttypes "github.com/docker/cli/cli/manifest/types" "github.com/docker/cli/internal/test" - "github.com/pkg/errors" + "gotest.tools/v3/assert" ) @@ -19,7 +21,7 @@ func newFakeRegistryClient() *fakeRegistryClient { return manifesttypes.ImageManifest{}, errors.New("") }, getManifestListFunc: func(_ context.Context, _ reference.Named) ([]manifesttypes.ImageManifest, error) { - return nil, errors.Errorf("") + return nil, fmt.Errorf("") }, } } diff --git a/cli/command/manifest/rm.go b/cli/command/manifest/rm.go index 2e2dc04624..1aaeeb020d 100644 --- a/cli/command/manifest/rm.go +++ b/cli/command/manifest/rm.go @@ -2,11 +2,12 @@ package manifest import ( "context" + "errors" "strings" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/network/connect_test.go b/cli/command/network/connect_test.go index c44fe3fc5f..749bb04ef8 100644 --- a/cli/command/network/connect_test.go +++ b/cli/command/network/connect_test.go @@ -2,12 +2,13 @@ package network import ( "context" + "fmt" "io" "testing" "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/network" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -24,7 +25,7 @@ func TestNetworkConnectErrors(t *testing.T) { { args: []string{"toto", "titi"}, networkConnectFunc: func(ctx context.Context, networkID, container string, config *network.EndpointSettings) error { - return errors.Errorf("error connecting network") + return fmt.Errorf("error connecting network") }, expectedError: "error connecting network", }, diff --git a/cli/command/network/create.go b/cli/command/network/create.go index 69374c5880..0ba3bb72de 100644 --- a/cli/command/network/create.go +++ b/cli/command/network/create.go @@ -13,7 +13,7 @@ import ( "github.com/docker/cli/opts" "github.com/docker/docker/api/types/network" "github.com/docker/docker/client" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -137,7 +137,7 @@ func runCreate(ctx context.Context, apiClient client.NetworkAPIClient, output io //nolint:gocyclo func createIPAMConfig(options ipamOptions) (*network.IPAM, error) { if len(options.subnets) < len(options.ipRanges) || len(options.subnets) < len(options.gateways) { - return nil, errors.Errorf("every ip-range or gateway must have a corresponding subnet") + return nil, fmt.Errorf("every ip-range or gateway must have a corresponding subnet") } iData := map[string]*network.IPAMConfig{} @@ -153,7 +153,7 @@ func createIPAMConfig(options ipamOptions) (*network.IPAM, error) { return nil, err } if ok1 || ok2 { - return nil, errors.Errorf("multiple overlapping subnet configuration is not supported") + return nil, fmt.Errorf("multiple overlapping subnet configuration is not supported") } } iData[s] = &network.IPAMConfig{Subnet: s, AuxAddress: map[string]string{}} @@ -174,14 +174,14 @@ func createIPAMConfig(options ipamOptions) (*network.IPAM, error) { continue } if iData[s].IPRange != "" { - return nil, errors.Errorf("cannot configure multiple ranges (%s, %s) on the same subnet (%s)", r, iData[s].IPRange, s) + return nil, fmt.Errorf("cannot configure multiple ranges (%s, %s) on the same subnet (%s)", r, iData[s].IPRange, s) } d := iData[s] d.IPRange = r match = true } if !match { - return nil, errors.Errorf("no matching subnet for range %s", r) + return nil, fmt.Errorf("no matching subnet for range %s", r) } } @@ -197,14 +197,14 @@ func createIPAMConfig(options ipamOptions) (*network.IPAM, error) { continue } if iData[s].Gateway != "" { - return nil, errors.Errorf("cannot configure multiple gateways (%s, %s) for the same subnet (%s)", g, iData[s].Gateway, s) + return nil, fmt.Errorf("cannot configure multiple gateways (%s, %s) for the same subnet (%s)", g, iData[s].Gateway, s) } d := iData[s] d.Gateway = g match = true } if !match { - return nil, errors.Errorf("no matching subnet for gateway %s", g) + return nil, fmt.Errorf("no matching subnet for gateway %s", g) } } @@ -223,7 +223,7 @@ func createIPAMConfig(options ipamOptions) (*network.IPAM, error) { match = true } if !match { - return nil, errors.Errorf("no matching subnet for aux-address %s", aa) + return nil, fmt.Errorf("no matching subnet for aux-address %s", aa) } } @@ -244,7 +244,7 @@ func subnetMatches(subnet, data string) (bool, error) { _, s, err := net.ParseCIDR(subnet) if err != nil { - return false, errors.Wrap(err, "invalid subnet") + return false, fmt.Errorf("invalid subnet: %w", err) } if strings.Contains(data, "/") { diff --git a/cli/command/network/create_test.go b/cli/command/network/create_test.go index 94ff0ffc97..986c62e3c0 100644 --- a/cli/command/network/create_test.go +++ b/cli/command/network/create_test.go @@ -2,13 +2,14 @@ package network import ( "context" + "fmt" "io" "strings" "testing" "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/network" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -26,7 +27,7 @@ func TestNetworkCreateErrors(t *testing.T) { { args: []string{"toto"}, networkCreateFunc: func(ctx context.Context, name string, createBody network.CreateOptions) (network.CreateResponse, error) { - return network.CreateResponse{}, errors.Errorf("error creating network") + return network.CreateResponse{}, fmt.Errorf("error creating network") }, expectedError: "error creating network", }, diff --git a/cli/command/network/disconnect_test.go b/cli/command/network/disconnect_test.go index bb82452a6c..2718e4f2bf 100644 --- a/cli/command/network/disconnect_test.go +++ b/cli/command/network/disconnect_test.go @@ -2,11 +2,12 @@ package network import ( "context" + "fmt" "io" "testing" "github.com/docker/cli/internal/test" - "github.com/pkg/errors" + "gotest.tools/v3/assert" ) @@ -22,7 +23,7 @@ func TestNetworkDisconnectErrors(t *testing.T) { { args: []string{"toto", "titi"}, networkDisconnectFunc: func(ctx context.Context, networkID, container string, force bool) error { - return errors.Errorf("error disconnecting network") + return fmt.Errorf("error disconnecting network") }, expectedError: "error disconnecting network", }, diff --git a/cli/command/network/list_test.go b/cli/command/network/list_test.go index e92c0d09fa..c2607ac2a5 100644 --- a/cli/command/network/list_test.go +++ b/cli/command/network/list_test.go @@ -2,6 +2,7 @@ package network import ( "context" + "fmt" "io" "testing" @@ -10,7 +11,7 @@ import ( "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/network" "github.com/google/go-cmp/cmp" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -23,7 +24,7 @@ func TestNetworkListErrors(t *testing.T) { }{ { networkListFunc: func(ctx context.Context, options network.ListOptions) ([]network.Summary, error) { - return []network.Summary{}, errors.Errorf("error creating network") + return []network.Summary{}, fmt.Errorf("error creating network") }, expectedError: "error creating network", }, diff --git a/cli/command/network/prune.go b/cli/command/network/prune.go index 36ff9e761d..0bae1c59e8 100644 --- a/cli/command/network/prune.go +++ b/cli/command/network/prune.go @@ -2,13 +2,14 @@ package network import ( "context" + "errors" "fmt" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/opts" "github.com/docker/docker/errdefs" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/network/prune_test.go b/cli/command/network/prune_test.go index 16010d3c74..67a57e8c8a 100644 --- a/cli/command/network/prune_test.go +++ b/cli/command/network/prune_test.go @@ -2,13 +2,13 @@ package network import ( "context" + "errors" "io" "testing" "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/network" - "github.com/pkg/errors" ) func TestNetworkPrunePromptTermination(t *testing.T) { diff --git a/cli/command/network/remove_test.go b/cli/command/network/remove_test.go index e3217a1874..faad56b742 100644 --- a/cli/command/network/remove_test.go +++ b/cli/command/network/remove_test.go @@ -2,13 +2,14 @@ package network import ( "context" + "errors" "io" "testing" "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/network" "github.com/docker/docker/errdefs" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) diff --git a/cli/command/node/demote_test.go b/cli/command/node/demote_test.go index ad7590533d..64edbf38d6 100644 --- a/cli/command/node/demote_test.go +++ b/cli/command/node/demote_test.go @@ -1,13 +1,14 @@ package node import ( + "fmt" "io" "testing" "github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "gotest.tools/v3/assert" ) @@ -24,14 +25,14 @@ func TestNodeDemoteErrors(t *testing.T) { { args: []string{"nodeID"}, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return swarm.Node{}, []byte{}, errors.Errorf("error inspecting the node") + return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting the node") }, expectedError: "error inspecting the node", }, { args: []string{"nodeID"}, nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error { - return errors.Errorf("error updating the node") + return fmt.Errorf("error updating the node") }, expectedError: "error updating the node", }, @@ -57,7 +58,7 @@ func TestNodeDemoteNoChange(t *testing.T) { }, nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error { if node.Role != swarm.NodeRoleWorker { - return errors.Errorf("expected role worker, got %s", node.Role) + return fmt.Errorf("expected role worker, got %s", node.Role) } return nil }, @@ -74,7 +75,7 @@ func TestNodeDemoteMultipleNode(t *testing.T) { }, nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error { if node.Role != swarm.NodeRoleWorker { - return errors.Errorf("expected role worker, got %s", node.Role) + return fmt.Errorf("expected role worker, got %s", node.Role) } return nil }, diff --git a/cli/command/node/inspect_test.go b/cli/command/node/inspect_test.go index 9cb742fbb9..969ac7bfcd 100644 --- a/cli/command/node/inspect_test.go +++ b/cli/command/node/inspect_test.go @@ -9,7 +9,7 @@ import ( "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/system" - "github.com/pkg/errors" + "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -28,24 +28,24 @@ func TestNodeInspectErrors(t *testing.T) { { args: []string{"self"}, infoFunc: func() (system.Info, error) { - return system.Info{}, errors.Errorf("error asking for node info") + return system.Info{}, fmt.Errorf("error asking for node info") }, expectedError: "error asking for node info", }, { args: []string{"nodeID"}, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return swarm.Node{}, []byte{}, errors.Errorf("error inspecting the node") + return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting the node") }, infoFunc: func() (system.Info, error) { - return system.Info{}, errors.Errorf("error asking for node info") + return system.Info{}, fmt.Errorf("error asking for node info") }, expectedError: "error inspecting the node", }, { args: []string{"self"}, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return swarm.Node{}, []byte{}, errors.Errorf("error inspecting the node") + return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting the node") }, infoFunc: func() (system.Info, error) { return system.Info{Swarm: swarm.Info{NodeID: "abc"}}, nil @@ -58,7 +58,7 @@ func TestNodeInspectErrors(t *testing.T) { "pretty": "true", }, infoFunc: func() (system.Info, error) { - return system.Info{}, errors.Errorf("error asking for node info") + return system.Info{}, fmt.Errorf("error asking for node info") }, expectedError: "error asking for node info", }, diff --git a/cli/command/node/list_test.go b/cli/command/node/list_test.go index 0ccf8a2d4e..1e6fd640ce 100644 --- a/cli/command/node/list_test.go +++ b/cli/command/node/list_test.go @@ -1,6 +1,7 @@ package node import ( + "fmt" "io" "testing" @@ -9,7 +10,7 @@ import ( "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/system" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -23,7 +24,7 @@ func TestNodeListErrorOnAPIFailure(t *testing.T) { }{ { nodeListFunc: func() ([]swarm.Node, error) { - return []swarm.Node{}, errors.Errorf("error listing nodes") + return []swarm.Node{}, fmt.Errorf("error listing nodes") }, expectedError: "error listing nodes", }, @@ -36,7 +37,7 @@ func TestNodeListErrorOnAPIFailure(t *testing.T) { }, nil }, infoFunc: func() (system.Info, error) { - return system.Info{}, errors.Errorf("error asking for node info") + return system.Info{}, fmt.Errorf("error asking for node info") }, expectedError: "error asking for node info", }, diff --git a/cli/command/node/promote_test.go b/cli/command/node/promote_test.go index bf4dce5395..9d0190c550 100644 --- a/cli/command/node/promote_test.go +++ b/cli/command/node/promote_test.go @@ -1,13 +1,14 @@ package node import ( + "fmt" "io" "testing" "github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "gotest.tools/v3/assert" ) @@ -24,14 +25,14 @@ func TestNodePromoteErrors(t *testing.T) { { args: []string{"nodeID"}, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return swarm.Node{}, []byte{}, errors.Errorf("error inspecting the node") + return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting the node") }, expectedError: "error inspecting the node", }, { args: []string{"nodeID"}, nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error { - return errors.Errorf("error updating the node") + return fmt.Errorf("error updating the node") }, expectedError: "error updating the node", }, @@ -57,7 +58,7 @@ func TestNodePromoteNoChange(t *testing.T) { }, nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error { if node.Role != swarm.NodeRoleManager { - return errors.Errorf("expected role manager, got %s", node.Role) + return fmt.Errorf("expected role manager, got %s", node.Role) } return nil }, @@ -74,7 +75,7 @@ func TestNodePromoteMultipleNode(t *testing.T) { }, nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error { if node.Role != swarm.NodeRoleManager { - return errors.Errorf("expected role manager, got %s", node.Role) + return fmt.Errorf("expected role manager, got %s", node.Role) } return nil }, diff --git a/cli/command/node/ps.go b/cli/command/node/ps.go index 207ecff575..2125a50b88 100644 --- a/cli/command/node/ps.go +++ b/cli/command/node/ps.go @@ -2,6 +2,7 @@ package node import ( "context" + "fmt" "strings" "github.com/docker/cli/cli" @@ -12,7 +13,7 @@ import ( "github.com/docker/cli/opts" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -98,7 +99,7 @@ func runPs(ctx context.Context, dockerCli command.Cli, options psOptions) error } if len(errs) > 0 { - return errors.Errorf("%s", strings.Join(errs, "\n")) + return fmt.Errorf("%s", strings.Join(errs, "\n")) } return nil diff --git a/cli/command/node/ps_test.go b/cli/command/node/ps_test.go index 84b1612170..7b522cdde7 100644 --- a/cli/command/node/ps_test.go +++ b/cli/command/node/ps_test.go @@ -12,7 +12,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/system" - "github.com/pkg/errors" + "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -29,21 +29,21 @@ func TestNodePsErrors(t *testing.T) { }{ { infoFunc: func() (system.Info, error) { - return system.Info{}, errors.Errorf("error asking for node info") + return system.Info{}, fmt.Errorf("error asking for node info") }, expectedError: "error asking for node info", }, { args: []string{"nodeID"}, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return swarm.Node{}, []byte{}, errors.Errorf("error inspecting the node") + return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting the node") }, expectedError: "error inspecting the node", }, { args: []string{"nodeID"}, taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) { - return []swarm.Task{}, errors.Errorf("error returning the task list") + return []swarm.Task{}, fmt.Errorf("error returning the task list") }, expectedError: "error returning the task list", }, diff --git a/cli/command/node/remove.go b/cli/command/node/remove.go index fedf34dec4..acca4254b2 100644 --- a/cli/command/node/remove.go +++ b/cli/command/node/remove.go @@ -8,7 +8,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/docker/api/types" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -48,7 +48,7 @@ func runRemove(ctx context.Context, dockerCli command.Cli, args []string, opts r } if len(errs) > 0 { - return errors.Errorf("%s", strings.Join(errs, "\n")) + return fmt.Errorf("%s", strings.Join(errs, "\n")) } return nil diff --git a/cli/command/node/remove_test.go b/cli/command/node/remove_test.go index 44b6342826..5791873455 100644 --- a/cli/command/node/remove_test.go +++ b/cli/command/node/remove_test.go @@ -1,11 +1,12 @@ package node import ( + "fmt" "io" "testing" "github.com/docker/cli/internal/test" - "github.com/pkg/errors" + "gotest.tools/v3/assert" ) @@ -21,7 +22,7 @@ func TestNodeRemoveErrors(t *testing.T) { { args: []string{"nodeID"}, nodeRemoveFunc: func() error { - return errors.Errorf("error removing the node") + return fmt.Errorf("error removing the node") }, expectedError: "error removing the node", }, diff --git a/cli/command/node/update.go b/cli/command/node/update.go index 2083aeaf5d..c3f197e6f5 100644 --- a/cli/command/node/update.go +++ b/cli/command/node/update.go @@ -2,13 +2,14 @@ package node import ( "context" + "errors" "fmt" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/opts" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -100,7 +101,7 @@ func mergeNodeUpdate(flags *pflag.FlagSet) func(*swarm.Node) error { for _, k := range keys { // if a key doesn't exist, fail the command explicitly if _, exists := spec.Annotations.Labels[k]; !exists { - return errors.Errorf("key %s doesn't exist in node's labels", k) + return fmt.Errorf("key %s doesn't exist in node's labels", k) } delete(spec.Annotations.Labels, k) } diff --git a/cli/command/node/update_test.go b/cli/command/node/update_test.go index 52e771a9ae..680bdc8da6 100644 --- a/cli/command/node/update_test.go +++ b/cli/command/node/update_test.go @@ -1,13 +1,14 @@ package node import ( + "fmt" "io" "testing" "github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "gotest.tools/v3/assert" ) @@ -29,14 +30,14 @@ func TestNodeUpdateErrors(t *testing.T) { { args: []string{"nodeID"}, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return swarm.Node{}, []byte{}, errors.Errorf("error inspecting the node") + return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting the node") }, expectedError: "error inspecting the node", }, { args: []string{"nodeID"}, nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error { - return errors.Errorf("error updating the node") + return fmt.Errorf("error updating the node") }, expectedError: "error updating the node", }, @@ -86,7 +87,7 @@ func TestNodeUpdate(t *testing.T) { }, nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error { if node.Role != swarm.NodeRoleManager { - return errors.Errorf("expected role manager, got %s", node.Role) + return fmt.Errorf("expected role manager, got %s", node.Role) } return nil }, @@ -101,7 +102,7 @@ func TestNodeUpdate(t *testing.T) { }, nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error { if node.Availability != swarm.NodeAvailabilityDrain { - return errors.Errorf("expected drain availability, got %s", node.Availability) + return fmt.Errorf("expected drain availability, got %s", node.Availability) } return nil }, @@ -116,7 +117,7 @@ func TestNodeUpdate(t *testing.T) { }, nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error { if _, present := node.Annotations.Labels["lbl"]; !present { - return errors.Errorf("expected 'lbl' label, got %v", node.Annotations.Labels) + return fmt.Errorf("expected 'lbl' label, got %v", node.Annotations.Labels) } return nil }, @@ -131,7 +132,7 @@ func TestNodeUpdate(t *testing.T) { }, nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error { if value, present := node.Annotations.Labels["key"]; !present || value != "value" { - return errors.Errorf("expected 'key' label to be 'value', got %v", node.Annotations.Labels) + return fmt.Errorf("expected 'key' label to be 'value', got %v", node.Annotations.Labels) } return nil }, @@ -148,7 +149,7 @@ func TestNodeUpdate(t *testing.T) { }, nodeUpdateFunc: func(nodeID string, version swarm.Version, node swarm.NodeSpec) error { if len(node.Annotations.Labels) > 0 { - return errors.Errorf("expected no labels, got %v", node.Annotations.Labels) + return fmt.Errorf("expected no labels, got %v", node.Annotations.Labels) } return nil }, diff --git a/cli/command/plugin/create.go b/cli/command/plugin/create.go index c81bab3338..060317408e 100644 --- a/cli/command/plugin/create.go +++ b/cli/command/plugin/create.go @@ -14,7 +14,7 @@ import ( "github.com/docker/cli/cli/command/completion" "github.com/docker/docker/api/types" "github.com/docker/docker/pkg/archive" - "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -52,7 +52,7 @@ func validateContextDir(contextDir string) (string, error) { } if !stat.IsDir() { - return "", errors.Errorf("context must be a directory") + return "", fmt.Errorf("context must be a directory") } return absContextDir, nil diff --git a/cli/command/plugin/enable.go b/cli/command/plugin/enable.go index e1724fd50c..86db11d78d 100644 --- a/cli/command/plugin/enable.go +++ b/cli/command/plugin/enable.go @@ -7,7 +7,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/docker/api/types" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -37,7 +37,7 @@ func newEnableCommand(dockerCli command.Cli) *cobra.Command { func runEnable(ctx context.Context, dockerCli command.Cli, opts *enableOpts) error { name := opts.name if opts.timeout < 0 { - return errors.Errorf("negative timeout %d is invalid", opts.timeout) + return fmt.Errorf("negative timeout %d is invalid", opts.timeout) } if err := dockerCli.Client().PluginEnable(ctx, name, types.PluginEnableOptions{Timeout: opts.timeout}); err != nil { diff --git a/cli/command/plugin/install.go b/cli/command/plugin/install.go index 6d9ea7da5f..a42ebf1f73 100644 --- a/cli/command/plugin/install.go +++ b/cli/command/plugin/install.go @@ -2,6 +2,7 @@ package plugin import ( "context" + "errors" "fmt" "strings" @@ -13,7 +14,7 @@ import ( registrytypes "github.com/docker/docker/api/types/registry" "github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/registry" - "github.com/pkg/errors" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -76,7 +77,7 @@ func buildPullConfig(ctx context.Context, dockerCli command.Cli, opts pluginOpti ref = reference.TagNameOnly(ref) nt, ok := ref.(reference.NamedTagged) if !ok { - return types.PluginInstallOptions{}, errors.Errorf("invalid name: %s", ref.String()) + return types.PluginInstallOptions{}, fmt.Errorf("invalid name: %s", ref.String()) } trusted, err := image.TrustedReference(ctx, dockerCli, nt) @@ -112,7 +113,7 @@ func runInstall(ctx context.Context, dockerCli command.Cli, opts pluginOptions) return err } if _, ok := aref.(reference.Canonical); ok { - return errors.Errorf("invalid name: %s", opts.localName) + return fmt.Errorf("invalid name: %s", opts.localName) } localName = reference.FamiliarString(reference.TagNameOnly(aref)) } diff --git a/cli/command/plugin/push.go b/cli/command/plugin/push.go index 7f8b5dcca4..fef7472bf0 100644 --- a/cli/command/plugin/push.go +++ b/cli/command/plugin/push.go @@ -2,6 +2,7 @@ package plugin import ( "context" + "fmt" "github.com/distribution/reference" "github.com/docker/cli/cli" @@ -10,7 +11,7 @@ import ( registrytypes "github.com/docker/docker/api/types/registry" "github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/registry" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -44,7 +45,7 @@ func runPush(ctx context.Context, dockerCli command.Cli, opts pushOptions) error return err } if _, ok := named.(reference.Canonical); ok { - return errors.Errorf("invalid name: %s", opts.name) + return fmt.Errorf("invalid name: %s", opts.name) } named = reference.TagNameOnly(named) diff --git a/cli/command/plugin/upgrade.go b/cli/command/plugin/upgrade.go index d609c8d01e..f78a2855e5 100644 --- a/cli/command/plugin/upgrade.go +++ b/cli/command/plugin/upgrade.go @@ -2,6 +2,7 @@ package plugin import ( "context" + "errors" "fmt" "strings" @@ -10,7 +11,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/jsonmessage" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -39,11 +40,11 @@ func newUpgradeCommand(dockerCli command.Cli) *cobra.Command { func runUpgrade(ctx context.Context, dockerCli command.Cli, opts pluginOptions) error { p, _, err := dockerCli.Client().PluginInspectWithRaw(ctx, opts.localName) if err != nil { - return errors.Errorf("error reading plugin data: %v", err) + return fmt.Errorf("error reading plugin data: %v", err) } if p.Enabled { - return errors.Errorf("the plugin must be disabled before upgrading") + return fmt.Errorf("the plugin must be disabled before upgrading") } opts.localName = p.Name @@ -52,13 +53,13 @@ func runUpgrade(ctx context.Context, dockerCli command.Cli, opts pluginOptions) } remote, err := reference.ParseNormalizedNamed(opts.remote) if err != nil { - return errors.Wrap(err, "error parsing remote upgrade image reference") + return fmt.Errorf("error parsing remote upgrade image reference: %w", err) } remote = reference.TagNameOnly(remote) old, err := reference.ParseNormalizedNamed(p.PluginReference) if err != nil { - return errors.Wrap(err, "error parsing current image reference") + return fmt.Errorf("error parsing current image reference: %w", err) } old = reference.TagNameOnly(old) diff --git a/cli/command/plugin/upgrade_test.go b/cli/command/plugin/upgrade_test.go index 006998b16f..3502886a02 100644 --- a/cli/command/plugin/upgrade_test.go +++ b/cli/command/plugin/upgrade_test.go @@ -2,12 +2,13 @@ package plugin import ( "context" + "errors" "io" "testing" "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types" - "github.com/pkg/errors" + "gotest.tools/v3/golden" ) diff --git a/cli/command/registry.go b/cli/command/registry.go index 7be5f5a290..08043f78d7 100644 --- a/cli/command/registry.go +++ b/cli/command/registry.go @@ -15,7 +15,6 @@ import ( "github.com/docker/cli/cli/streams" registrytypes "github.com/docker/docker/api/types/registry" "github.com/docker/docker/registry" - "github.com/pkg/errors" ) const patSuggest = "You can log in with your password or a Personal Access " + @@ -151,7 +150,7 @@ func PromptUserForCredentials(ctx context.Context, cli Cli, argUser, argPassword } } if argUser == "" { - return authConfig, errors.Errorf("Error: Non-null Username Required") + return authConfig, fmt.Errorf("Error: Non-null Username Required") } if argPassword == "" { restoreInput, err := DisableInputEcho(cli.In()) @@ -166,7 +165,7 @@ func PromptUserForCredentials(ctx context.Context, cli Cli, argUser, argPassword } fmt.Fprint(cli.Out(), "\n") if argPassword == "" { - return authConfig, errors.Errorf("Error: Password Required") + return authConfig, fmt.Errorf("Error: Password Required") } } diff --git a/cli/command/registry/login.go b/cli/command/registry/login.go index 5a9e8118f3..c6779e05f9 100644 --- a/cli/command/registry/login.go +++ b/cli/command/registry/login.go @@ -2,6 +2,7 @@ package registry import ( "context" + "errors" "fmt" "io" "os" @@ -17,7 +18,7 @@ import ( "github.com/docker/docker/client" "github.com/docker/docker/errdefs" "github.com/docker/docker/registry" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -163,7 +164,7 @@ func loginUser(ctx context.Context, dockerCli command.Cli, opts loginOptions, de // will hit this if you attempt docker login from mintty where stdin // is a pipe, not a character based console. if (opts.user == "" || opts.password == "") && !dockerCli.In().IsTerminal() { - return nil, errors.Errorf("Error: Cannot perform an interactive login from a non TTY device") + return nil, fmt.Errorf("Error: Cannot perform an interactive login from a non TTY device") } // If we're logging into the index server and the user didn't provide a username or password, use the device flow @@ -225,7 +226,7 @@ func loginWithDeviceCodeFlow(ctx context.Context, dockerCli command.Cli) (*regis func storeCredentials(dockerCli command.Cli, authConfig registrytypes.AuthConfig) error { creds := dockerCli.ConfigFile().GetCredentialsStore(authConfig.ServerAddress) if err := creds.Store(configtypes.AuthConfig(authConfig)); err != nil { - return errors.Errorf("Error saving credentials: %v", err) + return fmt.Errorf("Error saving credentials: %v", err) } return nil diff --git a/cli/command/secret/create.go b/cli/command/secret/create.go index 706e92c3d1..321806a47b 100644 --- a/cli/command/secret/create.go +++ b/cli/command/secret/create.go @@ -10,7 +10,7 @@ import ( "github.com/docker/cli/opts" "github.com/docker/docker/api/types/swarm" "github.com/moby/sys/sequential" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -53,12 +53,12 @@ func runSecretCreate(ctx context.Context, dockerCli command.Cli, options createO client := dockerCli.Client() if options.driver != "" && options.file != "" { - return errors.Errorf("When using secret driver secret data must be empty") + return fmt.Errorf("When using secret driver secret data must be empty") } secretData, err := readSecretData(dockerCli.In(), options.file) if err != nil { - return errors.Errorf("Error reading content from %q: %v", options.file, err) + return fmt.Errorf("Error reading content from %q: %v", options.file, err) } spec := swarm.SecretSpec{ Annotations: swarm.Annotations{ diff --git a/cli/command/secret/create_test.go b/cli/command/secret/create_test.go index 41c7b853da..737f171597 100644 --- a/cli/command/secret/create_test.go +++ b/cli/command/secret/create_test.go @@ -2,6 +2,7 @@ package secret import ( "context" + "fmt" "io" "os" "path/filepath" @@ -12,7 +13,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -36,7 +37,7 @@ func TestSecretCreateErrors(t *testing.T) { { args: []string{"name", filepath.Join("testdata", secretDataFile)}, secretCreateFunc: func(_ context.Context, secretSpec swarm.SecretSpec) (types.SecretCreateResponse, error) { - return types.SecretCreateResponse{}, errors.Errorf("error creating secret") + return types.SecretCreateResponse{}, fmt.Errorf("error creating secret") }, expectedError: "error creating secret", }, @@ -70,7 +71,7 @@ func TestSecretCreateWithName(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ secretCreateFunc: func(_ context.Context, spec swarm.SecretSpec) (types.SecretCreateResponse, error) { if !reflect.DeepEqual(spec, expected) { - return types.SecretCreateResponse{}, errors.Errorf("expected %+v, got %+v", expected, spec) + return types.SecretCreateResponse{}, fmt.Errorf("expected %+v, got %+v", expected, spec) } return types.SecretCreateResponse{ ID: "ID-" + spec.Name, @@ -93,11 +94,11 @@ func TestSecretCreateWithDriver(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ secretCreateFunc: func(_ context.Context, spec swarm.SecretSpec) (types.SecretCreateResponse, error) { if spec.Name != name { - return types.SecretCreateResponse{}, errors.Errorf("expected name %q, got %q", name, spec.Name) + return types.SecretCreateResponse{}, fmt.Errorf("expected name %q, got %q", name, spec.Name) } if spec.Driver.Name != expectedDriver.Name { - return types.SecretCreateResponse{}, errors.Errorf("expected driver %v, got %v", expectedDriver, spec.Labels) + return types.SecretCreateResponse{}, fmt.Errorf("expected driver %v, got %v", expectedDriver, spec.Labels) } return types.SecretCreateResponse{ @@ -122,11 +123,11 @@ func TestSecretCreateWithTemplatingDriver(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ secretCreateFunc: func(_ context.Context, spec swarm.SecretSpec) (types.SecretCreateResponse, error) { if spec.Name != name { - return types.SecretCreateResponse{}, errors.Errorf("expected name %q, got %q", name, spec.Name) + return types.SecretCreateResponse{}, fmt.Errorf("expected name %q, got %q", name, spec.Name) } if spec.Templating.Name != expectedDriver.Name { - return types.SecretCreateResponse{}, errors.Errorf("expected driver %v, got %v", expectedDriver, spec.Labels) + return types.SecretCreateResponse{}, fmt.Errorf("expected driver %v, got %v", expectedDriver, spec.Labels) } return types.SecretCreateResponse{ @@ -152,11 +153,11 @@ func TestSecretCreateWithLabels(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ secretCreateFunc: func(_ context.Context, spec swarm.SecretSpec) (types.SecretCreateResponse, error) { if spec.Name != name { - return types.SecretCreateResponse{}, errors.Errorf("expected name %q, got %q", name, spec.Name) + return types.SecretCreateResponse{}, fmt.Errorf("expected name %q, got %q", name, spec.Name) } if !reflect.DeepEqual(spec.Labels, expectedLabels) { - return types.SecretCreateResponse{}, errors.Errorf("expected labels %v, got %v", expectedLabels, spec.Labels) + return types.SecretCreateResponse{}, fmt.Errorf("expected labels %v, got %v", expectedLabels, spec.Labels) } return types.SecretCreateResponse{ diff --git a/cli/command/secret/inspect_test.go b/cli/command/secret/inspect_test.go index ca509c1249..e59313b716 100644 --- a/cli/command/secret/inspect_test.go +++ b/cli/command/secret/inspect_test.go @@ -10,7 +10,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -28,7 +28,7 @@ func TestSecretInspectErrors(t *testing.T) { { args: []string{"foo"}, secretInspectFunc: func(_ context.Context, secretID string) (swarm.Secret, []byte, error) { - return swarm.Secret{}, nil, errors.Errorf("error while inspecting the secret") + return swarm.Secret{}, nil, fmt.Errorf("error while inspecting the secret") }, expectedError: "error while inspecting the secret", }, @@ -45,7 +45,7 @@ func TestSecretInspectErrors(t *testing.T) { if secretID == "foo" { return *builders.Secret(builders.SecretName("foo")), nil, nil } - return swarm.Secret{}, nil, errors.Errorf("error while inspecting the secret") + return swarm.Secret{}, nil, fmt.Errorf("error while inspecting the secret") }, expectedError: "error while inspecting the secret", }, @@ -77,7 +77,7 @@ func TestSecretInspectWithoutFormat(t *testing.T) { args: []string{"foo"}, secretInspectFunc: func(_ context.Context, name string) (swarm.Secret, []byte, error) { if name != "foo" { - return swarm.Secret{}, nil, errors.Errorf("Invalid name, expected %s, got %s", "foo", name) + return swarm.Secret{}, nil, fmt.Errorf("Invalid name, expected %s, got %s", "foo", name) } return *builders.Secret(builders.SecretID("ID-foo"), builders.SecretName("foo")), nil, nil }, diff --git a/cli/command/secret/ls_test.go b/cli/command/secret/ls_test.go index 161e32f2ce..0ae2d3c8e6 100644 --- a/cli/command/secret/ls_test.go +++ b/cli/command/secret/ls_test.go @@ -2,6 +2,7 @@ package secret import ( "context" + "fmt" "io" "testing" "time" @@ -11,7 +12,7 @@ import ( "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -29,7 +30,7 @@ func TestSecretListErrors(t *testing.T) { }, { secretListFunc: func(_ context.Context, options types.SecretListOptions) ([]swarm.Secret, error) { - return []swarm.Secret{}, errors.Errorf("error listing secrets") + return []swarm.Secret{}, fmt.Errorf("error listing secrets") }, expectedError: "error listing secrets", }, diff --git a/cli/command/secret/remove.go b/cli/command/secret/remove.go index e51d03d345..88deffc6c3 100644 --- a/cli/command/secret/remove.go +++ b/cli/command/secret/remove.go @@ -7,7 +7,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -48,7 +48,7 @@ func runSecretRemove(ctx context.Context, dockerCli command.Cli, opts removeOpti } if len(errs) > 0 { - return errors.Errorf("%s", strings.Join(errs, "\n")) + return fmt.Errorf("%s", strings.Join(errs, "\n")) } return nil diff --git a/cli/command/secret/remove_test.go b/cli/command/secret/remove_test.go index b5f4889a8c..d4d9eec4f7 100644 --- a/cli/command/secret/remove_test.go +++ b/cli/command/secret/remove_test.go @@ -2,12 +2,13 @@ package secret import ( "context" + "fmt" "io" "strings" "testing" "github.com/docker/cli/internal/test" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -25,7 +26,7 @@ func TestSecretRemoveErrors(t *testing.T) { { args: []string{"foo"}, secretRemoveFunc: func(_ context.Context, name string) error { - return errors.Errorf("error removing secret") + return fmt.Errorf("error removing secret") }, expectedError: "error removing secret", }, @@ -67,7 +68,7 @@ func TestSecretRemoveContinueAfterError(t *testing.T) { secretRemoveFunc: func(_ context.Context, name string) error { removedSecrets = append(removedSecrets, name) if name == "foo" { - return errors.Errorf("error removing secret: %s", name) + return fmt.Errorf("error removing secret: %s", name) } return nil }, diff --git a/cli/command/service/formatter.go b/cli/command/service/formatter.go index 9e043713be..c19086ffe6 100644 --- a/cli/command/service/formatter.go +++ b/cli/command/service/formatter.go @@ -17,7 +17,6 @@ import ( "github.com/docker/docker/pkg/stringid" units "github.com/docker/go-units" "github.com/fvbommel/sortorder" - "github.com/pkg/errors" ) const serviceInspectPrettyTemplate formatter.Format = ` @@ -231,7 +230,7 @@ func InspectFormatWrite(ctx formatter.Context, refs []string, getRef, getNetwork } service, ok := serviceI.(swarm.Service) if !ok { - return errors.Errorf("got wrong object to inspect") + return fmt.Errorf("got wrong object to inspect") } if err := format(&serviceInspectContext{Service: service, networkNames: resolveNetworks(service, getNetwork)}); err != nil { return err diff --git a/cli/command/service/generic_resource_opts.go b/cli/command/service/generic_resource_opts.go index 613c255749..e895f2bd68 100644 --- a/cli/command/service/generic_resource_opts.go +++ b/cli/command/service/generic_resource_opts.go @@ -4,8 +4,6 @@ import ( "fmt" "strings" - "github.com/pkg/errors" - "github.com/docker/docker/api/types/swarm" swarmapi "github.com/moby/swarmkit/v2/api" "github.com/moby/swarmkit/v2/api/genericresource" @@ -37,7 +35,7 @@ func ParseGenericResources(value []string) ([]swarm.GenericResource, error) { resources, err := genericresource.Parse(value) if err != nil { - return nil, errors.Wrapf(err, "invalid generic resource specification") + return nil, fmt.Errorf("invalid generic resource specification: %w", err) } swarmResources := genericResourcesFromGRPC(resources) diff --git a/cli/command/service/inspect.go b/cli/command/service/inspect.go index fcd85c1209..5bf66469db 100644 --- a/cli/command/service/inspect.go +++ b/cli/command/service/inspect.go @@ -5,6 +5,7 @@ package service import ( "context" + "fmt" "strings" "github.com/docker/cli/cli" @@ -14,7 +15,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/network" "github.com/docker/docker/errdefs" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -35,7 +36,7 @@ func newInspectCommand(dockerCli command.Cli) *cobra.Command { opts.refs = args if opts.pretty && len(opts.format) > 0 { - return errors.Errorf("--format is incompatible with human friendly format") + return fmt.Errorf("--format is incompatible with human friendly format") } return runInspect(cmd.Context(), dockerCli, opts) }, @@ -63,7 +64,7 @@ func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions) if err == nil || !errdefs.IsNotFound(err) { return service, nil, err } - return nil, nil, errors.Errorf("Error: no such service: %s", ref) + return nil, nil, fmt.Errorf("Error: no such service: %s", ref) } getNetwork := func(ref string) (any, []byte, error) { @@ -71,7 +72,7 @@ func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions) if err == nil || !errdefs.IsNotFound(err) { return nw, nil, err } - return nil, nil, errors.Errorf("Error: no such network: %s", ref) + return nil, nil, fmt.Errorf("Error: no such network: %s", ref) } f := opts.format @@ -85,7 +86,7 @@ func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions) // check if the user is trying to apply a template to the pretty format, which // is not supported if strings.HasPrefix(f, "pretty") && f != "pretty" { - return errors.Errorf("Cannot supply extra formatting options to the pretty template") + return fmt.Errorf("Cannot supply extra formatting options to the pretty template") } serviceCtx := formatter.Context{ diff --git a/cli/command/service/logs.go b/cli/command/service/logs.go index b9f964aec9..42812d3993 100644 --- a/cli/command/service/logs.go +++ b/cli/command/service/logs.go @@ -3,6 +3,7 @@ package service import ( "bytes" "context" + "errors" "fmt" "io" "sort" @@ -20,7 +21,7 @@ import ( "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/stdcopy" "github.com/docker/docker/pkg/stringid" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -255,7 +256,7 @@ func (lw *logWriter) Write(buf []byte) (int, error) { // break up the log line into parts. parts := bytes.SplitN(buf, []byte(" "), numParts) if len(parts) != numParts { - return 0, errors.Errorf("invalid context in log message: %v", string(buf)) + return 0, fmt.Errorf("invalid context in log message: %v", string(buf)) } // parse the details out details, err := logs.ParseLogDetails(string(parts[detailsIndex])) @@ -320,19 +321,19 @@ func (lw *logWriter) Write(buf []byte) (int, error) { func (lw *logWriter) parseContext(details map[string]string) (logContext, error) { nodeID, ok := details["com.docker.swarm.node.id"] if !ok { - return logContext{}, errors.Errorf("missing node id in details: %v", details) + return logContext{}, fmt.Errorf("missing node id in details: %v", details) } delete(details, "com.docker.swarm.node.id") serviceID, ok := details["com.docker.swarm.service.id"] if !ok { - return logContext{}, errors.Errorf("missing service id in details: %v", details) + return logContext{}, fmt.Errorf("missing service id in details: %v", details) } delete(details, "com.docker.swarm.service.id") taskID, ok := details["com.docker.swarm.task.id"] if !ok { - return logContext{}, errors.Errorf("missing task id in details: %s", details) + return logContext{}, fmt.Errorf("missing task id in details: %s", details) } delete(details, "com.docker.swarm.task.id") diff --git a/cli/command/service/opts.go b/cli/command/service/opts.go index 79f545445a..def6df3512 100644 --- a/cli/command/service/opts.go +++ b/cli/command/service/opts.go @@ -5,6 +5,7 @@ package service import ( "context" + "errors" "fmt" "sort" "strconv" @@ -21,7 +22,7 @@ import ( "github.com/google/shlex" "github.com/moby/swarmkit/v2/api" "github.com/moby/swarmkit/v2/api/defaults" - "github.com/pkg/errors" + "github.com/spf13/pflag" ) @@ -101,7 +102,7 @@ func (o *placementPrefOpts) Set(value string) error { return errors.New(`placement preference must be of the format "="`) } if strategy != "spread" { - return errors.Errorf("unsupported placement preference %s (only spread is supported)", strategy) + return fmt.Errorf("unsupported placement preference %s (only spread is supported)", strategy) } o.prefs = append(o.prefs, swarm.PlacementPreference{ @@ -446,7 +447,7 @@ func (o *healthCheckOptions) toHealthConfig() (*container.HealthConfig, error) { o.retries != 0 if o.noHealthcheck { if haveHealthSettings { - return nil, errors.Errorf("--%s conflicts with --health-* options", flagNoHealthcheck) + return nil, fmt.Errorf("--%s conflicts with --health-* options", flagNoHealthcheck) } healthConfig = &container.HealthConfig{Test: []string{"NONE"}} } else if haveHealthSettings { @@ -584,7 +585,7 @@ func (options *serviceOptions) ToServiceMode() (swarm.ServiceMode, error) { switch options.mode { case "global": if options.replicas.Value() != nil { - return serviceMode, errors.Errorf("replicas can only be used with replicated or replicated-job mode") + return serviceMode, fmt.Errorf("replicas can only be used with replicated or replicated-job mode") } if options.maxReplicas > 0 { @@ -620,11 +621,11 @@ func (options *serviceOptions) ToServiceMode() (swarm.ServiceMode, error) { return serviceMode, errors.New("max-concurrent can only be used with replicated-job mode") } if options.replicas.Value() != nil { - return serviceMode, errors.Errorf("replicas can only be used with replicated or replicated-job mode") + return serviceMode, fmt.Errorf("replicas can only be used with replicated or replicated-job mode") } serviceMode.GlobalJob = &swarm.GlobalJob{} default: - return serviceMode, errors.Errorf("Unknown mode: %s, only replicated and global supported", options.mode) + return serviceMode, fmt.Errorf("Unknown mode: %s, only replicated and global supported", options.mode) } return serviceMode, nil } @@ -692,7 +693,7 @@ func (options *serviceOptions) ToService(ctx context.Context, apiClient client.N // flags are not set, then the values will be nil. If they are non-nil, // then return an error. if (serviceMode.ReplicatedJob != nil || serviceMode.GlobalJob != nil) && (updateConfig != nil || rollbackConfig != nil) { - return service, errors.Errorf("update and rollback configuration is not supported for jobs") + return service, fmt.Errorf("update and rollback configuration is not supported for jobs") } networks := convertNetworks(options.networks) diff --git a/cli/command/service/parse.go b/cli/command/service/parse.go index 239be18810..6b1bc2af63 100644 --- a/cli/command/service/parse.go +++ b/cli/command/service/parse.go @@ -2,12 +2,12 @@ package service import ( "context" + "fmt" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" swarmtypes "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" - "github.com/pkg/errors" ) // ParseSecrets retrieves the secrets with the requested names and fills @@ -21,7 +21,7 @@ func ParseSecrets(ctx context.Context, apiClient client.SecretAPIClient, request for _, secret := range requestedSecrets { if _, exists := secretRefs[secret.File.Name]; exists { - return nil, errors.Errorf("duplicate secret target for %s not allowed", secret.SecretName) + return nil, fmt.Errorf("duplicate secret target for %s not allowed", secret.SecretName) } secretRef := new(swarmtypes.SecretReference) *secretRef = *secret @@ -50,7 +50,7 @@ func ParseSecrets(ctx context.Context, apiClient client.SecretAPIClient, request for _, ref := range secretRefs { id, ok := foundSecrets[ref.SecretName] if !ok { - return nil, errors.Errorf("secret not found: %s", ref.SecretName) + return nil, fmt.Errorf("secret not found: %s", ref.SecretName) } // set the id for the ref to properly assign in swarm @@ -99,7 +99,7 @@ func ParseConfigs(ctx context.Context, apiClient client.ConfigAPIClient, request } if _, exists := configRefs[config.File.Name]; exists { - return nil, errors.Errorf("duplicate config target for %s not allowed", config.ConfigName) + return nil, fmt.Errorf("duplicate config target for %s not allowed", config.ConfigName) } configRefs[config.File.Name] = configRef @@ -130,7 +130,7 @@ func ParseConfigs(ctx context.Context, apiClient client.ConfigAPIClient, request for _, ref := range configRefs { id, ok := foundConfigs[ref.ConfigName] if !ok { - return nil, errors.Errorf("config not found: %s", ref.ConfigName) + return nil, fmt.Errorf("config not found: %s", ref.ConfigName) } // set the id for the ref to properly assign in swarm @@ -145,7 +145,7 @@ func ParseConfigs(ctx context.Context, apiClient client.ConfigAPIClient, request for _, ref := range runtimeRefs { id, ok := foundConfigs[ref.ConfigName] if !ok { - return nil, errors.Errorf("config not found: %s", ref.ConfigName) + return nil, fmt.Errorf("config not found: %s", ref.ConfigName) } ref.ConfigID = id diff --git a/cli/command/service/ps.go b/cli/command/service/ps.go index 126d9ace2f..1b938ac4d6 100644 --- a/cli/command/service/ps.go +++ b/cli/command/service/ps.go @@ -2,6 +2,7 @@ package service import ( "context" + "errors" "strings" "github.com/docker/cli/cli" @@ -13,7 +14,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/client" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/service/remove.go b/cli/command/service/remove.go index efbd5f9ad0..95e5cfdec4 100644 --- a/cli/command/service/remove.go +++ b/cli/command/service/remove.go @@ -2,12 +2,13 @@ package service import ( "context" + "errors" "fmt" "strings" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/service/scale.go b/cli/command/service/scale.go index 688a3ff2d0..1c9eedad9b 100644 --- a/cli/command/service/scale.go +++ b/cli/command/service/scale.go @@ -2,6 +2,7 @@ package service import ( "context" + "errors" "fmt" "strconv" "strings" @@ -10,7 +11,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/versions" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -44,7 +45,7 @@ func scaleArgs(cmd *cobra.Command, args []string) error { } for _, arg := range args { if k, v, ok := strings.Cut(arg, "="); !ok || k == "" || v == "" { - return errors.Errorf( + return fmt.Errorf( "Invalid scale specifier '%s'.\nSee '%s --help'.\n\nUsage: %s\n\n%s", arg, cmd.CommandPath(), @@ -108,7 +109,7 @@ func runServiceScale(ctx context.Context, dockerCli command.Cli, serviceID strin case serviceMode.ReplicatedJob != nil: serviceMode.ReplicatedJob.TotalCompletions = &scale default: - return errors.Errorf("scale can only be used with replicated or replicated-job mode") + return fmt.Errorf("scale can only be used with replicated or replicated-job mode") } response, err := client.ServiceUpdate(ctx, service.ID, service.Version, service.Spec, types.ServiceUpdateOptions{}) diff --git a/cli/command/service/trust.go b/cli/command/service/trust.go index 3aec19002e..3300ee2015 100644 --- a/cli/command/service/trust.go +++ b/cli/command/service/trust.go @@ -2,6 +2,8 @@ package service import ( "encoding/hex" + "errors" + "fmt" "github.com/distribution/reference" "github.com/docker/cli/cli/command" @@ -9,7 +11,7 @@ import ( "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/registry" "github.com/opencontainers/go-digest" - "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/theupdateframework/notary/tuf/data" ) @@ -23,7 +25,7 @@ func resolveServiceImageDigestContentTrust(dockerCli command.Cli, service *swarm ref, err := reference.ParseAnyReference(service.TaskTemplate.ContainerSpec.Image) if err != nil { - return errors.Wrapf(err, "invalid reference %s", service.TaskTemplate.ContainerSpec.Image) + return fmt.Errorf("invalid reference %s: %w", service.TaskTemplate.ContainerSpec.Image, err) } // If reference does not have digest (is not canonical nor image id) @@ -40,7 +42,7 @@ func resolveServiceImageDigestContentTrust(dockerCli command.Cli, service *swarm resolvedImage, err := trustedResolveDigest(dockerCli, taggedRef) if err != nil { - return errors.Wrap(err, "failed to resolve image digest using content trust") + return fmt.Errorf("failed to resolve image digest using content trust: %w", err) } resolvedFamiliar := reference.FamiliarString(resolvedImage) logrus.Debugf("resolved image tag to %s using content trust", resolvedFamiliar) @@ -60,7 +62,7 @@ func trustedResolveDigest(cli command.Cli, ref reference.NamedTagged) (reference notaryRepo, err := trust.GetNotaryRepository(cli.In(), cli.Out(), command.UserAgent(), repoInfo, &authConfig, "pull") if err != nil { - return nil, errors.Wrap(err, "error establishing connection to trust repository") + return nil, fmt.Errorf("error establishing connection to trust repository: %w", err) } t, err := notaryRepo.GetTargetByName(ref.Tag(), trust.ReleasesRole, data.CanonicalTargetsRole) @@ -70,7 +72,7 @@ func trustedResolveDigest(cli command.Cli, ref reference.NamedTagged) (reference // Only get the tag if it's in the top level targets role or the releases delegation role // ignore it if it's in any other delegation roles if t.Role != trust.ReleasesRole && t.Role != data.CanonicalTargetsRole { - return nil, trust.NotaryError(repoInfo.Name.Name(), errors.Errorf("No trust data for %s", reference.FamiliarString(ref))) + return nil, trust.NotaryError(repoInfo.Name.Name(), fmt.Errorf("No trust data for %s", reference.FamiliarString(ref))) } logrus.Debugf("retrieving target for %s role\n", t.Role) diff --git a/cli/command/service/update.go b/cli/command/service/update.go index d8f89185ae..4ed7fb3173 100644 --- a/cli/command/service/update.go +++ b/cli/command/service/update.go @@ -2,6 +2,7 @@ package service import ( "context" + "errors" "fmt" "sort" "strings" @@ -18,7 +19,7 @@ import ( "github.com/docker/docker/api/types/versions" "github.com/docker/docker/client" "github.com/moby/swarmkit/v2/api/defaults" - "github.com/pkg/errors" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -170,7 +171,7 @@ func runUpdate(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet, clientSideRollback = true spec = service.PreviousSpec if spec == nil { - return errors.Errorf("service does not have a previous specification to roll back to") + return fmt.Errorf("service does not have a previous specification to roll back to") } } else { serverSideRollback = true @@ -927,7 +928,7 @@ func updateMounts(flags *pflag.FlagSet, mounts *[]mounttypes.Mount) error { values := flags.Lookup(flagMountAdd).Value.(*opts.MountOpt).Value() for _, mount := range values { if _, ok := mountsByTarget[mount.Target]; ok { - return errors.Errorf("duplicate mount target") + return fmt.Errorf("duplicate mount target") } mountsByTarget[mount.Target] = mount } @@ -1123,7 +1124,7 @@ func updateReplicas(flags *pflag.FlagSet, serviceMode *swarm.ServiceMode) error } if serviceMode == nil || serviceMode.Replicated == nil { - return errors.Errorf("replicas can only be used with replicated mode") + return fmt.Errorf("replicas can only be used with replicated mode") } serviceMode.Replicated.Replicas = flags.Lookup(flagReplicas).Value.(*Uint64Opt).Value() return nil @@ -1263,7 +1264,7 @@ func updateHealthcheck(flags *pflag.FlagSet, containerSpec *swarm.ContainerSpec) } return nil } - return errors.Errorf("--%s conflicts with --health-* options", flagNoHealthcheck) + return fmt.Errorf("--%s conflicts with --health-* options", flagNoHealthcheck) } if len(containerSpec.Healthcheck.Test) > 0 && containerSpec.Healthcheck.Test[0] == "NONE" { containerSpec.Healthcheck.Test = nil @@ -1334,7 +1335,7 @@ func updateNetworks(ctx context.Context, apiClient client.NetworkAPIClient, flag return err } if _, exists := existingNetworks[nwID]; exists { - return errors.Errorf("service is already attached to network %s", nw.Target) + return fmt.Errorf("service is already attached to network %s", nw.Target) } nw.Target = nwID newNetworks = append(newNetworks, nw) diff --git a/cli/command/stack/list_test.go b/cli/command/stack/list_test.go index be76aa7e3d..0f03c47682 100644 --- a/cli/command/stack/list_test.go +++ b/cli/command/stack/list_test.go @@ -1,6 +1,7 @@ package stack import ( + "fmt" "io" "testing" @@ -8,7 +9,7 @@ import ( "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -34,7 +35,7 @@ func TestListErrors(t *testing.T) { { args: []string{}, serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) { - return []swarm.Service{}, errors.Errorf("error getting services") + return []swarm.Service{}, fmt.Errorf("error getting services") }, expectedError: "error getting services", }, diff --git a/cli/command/stack/loader/loader.go b/cli/command/stack/loader/loader.go index 7521d0471d..f825117f47 100644 --- a/cli/command/stack/loader/loader.go +++ b/cli/command/stack/loader/loader.go @@ -4,6 +4,7 @@ package loader 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 Config and version. @@ -32,7 +32,7 @@ func LoadComposefile(dockerCli command.Cli, opts options.Deploy) (*composetypes. if err != nil { if fpe, ok := err.(*loader.ForbiddenPropertiesError); ok { // 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)) } return nil, err @@ -122,7 +122,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 diff --git a/cli/command/stack/ps_test.go b/cli/command/stack/ps_test.go index 009d51ed83..bd78dd0d65 100644 --- a/cli/command/stack/ps_test.go +++ b/cli/command/stack/ps_test.go @@ -1,6 +1,7 @@ package stack import ( + "fmt" "io" "testing" "time" @@ -10,7 +11,7 @@ import ( "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -33,7 +34,7 @@ func TestStackPsErrors(t *testing.T) { { args: []string{"foo"}, taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) { - return nil, errors.Errorf("error getting tasks") + return nil, fmt.Errorf("error getting tasks") }, expectedError: "error getting tasks", }, diff --git a/cli/command/stack/services_test.go b/cli/command/stack/services_test.go index 8d24a4e49e..0e72f3ba98 100644 --- a/cli/command/stack/services_test.go +++ b/cli/command/stack/services_test.go @@ -1,6 +1,7 @@ package stack import ( + "fmt" "io" "testing" @@ -9,7 +10,7 @@ import ( "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -27,7 +28,7 @@ func TestStackServicesErrors(t *testing.T) { { args: []string{"foo"}, serviceListFunc: func(options types.ServiceListOptions) ([]swarm.Service, error) { - return nil, errors.Errorf("error getting services") + return nil, fmt.Errorf("error getting services") }, expectedError: "error getting services", }, @@ -37,7 +38,7 @@ func TestStackServicesErrors(t *testing.T) { return []swarm.Service{*builders.Service(builders.GlobalService())}, nil }, nodeListFunc: func(options types.NodeListOptions) ([]swarm.Node, error) { - return nil, errors.Errorf("error getting nodes") + return nil, fmt.Errorf("error getting nodes") }, taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) { return []swarm.Task{*builders.Task()}, nil @@ -50,7 +51,7 @@ func TestStackServicesErrors(t *testing.T) { return []swarm.Service{*builders.Service(builders.GlobalService())}, nil }, taskListFunc: func(options types.TaskListOptions) ([]swarm.Task, error) { - return nil, errors.Errorf("error getting tasks") + return nil, fmt.Errorf("error getting tasks") }, expectedError: "error getting tasks", }, diff --git a/cli/command/stack/swarm/deploy.go b/cli/command/stack/swarm/deploy.go index 7fe52f67fd..506f68047e 100644 --- a/cli/command/stack/swarm/deploy.go +++ b/cli/command/stack/swarm/deploy.go @@ -2,6 +2,7 @@ package swarm import ( "context" + "errors" "fmt" "github.com/docker/cli/cli/command" @@ -10,7 +11,7 @@ import ( composetypes "github.com/docker/cli/cli/compose/types" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/versions" - "github.com/pkg/errors" + "github.com/spf13/pflag" ) @@ -47,7 +48,7 @@ func validateResolveImageFlag(opts *options.Deploy) error { case ResolveImageAlways, ResolveImageChanged, ResolveImageNever: return nil 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) } } diff --git a/cli/command/stack/swarm/deploy_composefile_test.go b/cli/command/stack/swarm/deploy_composefile_test.go index 0cb66e8b44..d0320d6653 100644 --- a/cli/command/stack/swarm/deploy_composefile_test.go +++ b/cli/command/stack/swarm/deploy_composefile_test.go @@ -2,11 +2,12 @@ package swarm import ( "context" + "errors" "testing" "github.com/docker/cli/internal/test/network" networktypes "github.com/docker/docker/api/types/network" - "github.com/pkg/errors" + "gotest.tools/v3/assert" ) diff --git a/cli/command/stack/swarm/list.go b/cli/command/stack/swarm/list.go index 4c58b3de93..e94c99d467 100644 --- a/cli/command/stack/swarm/list.go +++ b/cli/command/stack/swarm/list.go @@ -2,12 +2,12 @@ package swarm import ( "context" + "fmt" "github.com/docker/cli/cli/command/stack/formatter" "github.com/docker/cli/cli/compose/convert" "github.com/docker/docker/api/types" "github.com/docker/docker/client" - "github.com/pkg/errors" ) // GetStacks lists the swarm stacks. @@ -23,7 +23,7 @@ func GetStacks(ctx context.Context, apiClient client.ServiceAPIClient) ([]*forma labels := service.Spec.Labels name, ok := labels[convert.LabelNamespace] if !ok { - return nil, errors.Errorf("cannot get label %s for service %s", + return nil, fmt.Errorf("cannot get label %s for service %s", convert.LabelNamespace, service.ID) } ztack, ok := m[name] diff --git a/cli/command/stack/swarm/remove.go b/cli/command/stack/swarm/remove.go index 5641ea24bd..dbcd837c9c 100644 --- a/cli/command/stack/swarm/remove.go +++ b/cli/command/stack/swarm/remove.go @@ -2,6 +2,7 @@ package swarm import ( "context" + "errors" "fmt" "sort" "strings" @@ -12,7 +13,6 @@ import ( "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/versions" "github.com/docker/docker/client" - "github.com/pkg/errors" ) // RunRemove is the swarm implementation of docker stack remove diff --git a/cli/command/swarm/ca.go b/cli/command/swarm/ca.go index 25c235a450..82ebebfc89 100644 --- a/cli/command/swarm/ca.go +++ b/cli/command/swarm/ca.go @@ -2,6 +2,7 @@ package swarm import ( "context" + "errors" "fmt" "io" "strings" @@ -12,7 +13,7 @@ import ( "github.com/docker/cli/cli/command/swarm/progress" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/pkg/jsonmessage" - "github.com/pkg/errors" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) diff --git a/cli/command/swarm/init.go b/cli/command/swarm/init.go index 8612a5f8f1..90cf2df5c3 100644 --- a/cli/command/swarm/init.go +++ b/cli/command/swarm/init.go @@ -2,6 +2,7 @@ package swarm import ( "context" + "errors" "fmt" "net" "strings" @@ -10,7 +11,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -89,7 +90,7 @@ func runInit(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet, o case swarm.NodeAvailabilityActive, swarm.NodeAvailabilityPause, swarm.NodeAvailabilityDrain: req.Availability = availability default: - return errors.Errorf("invalid availability %q, only active, pause and drain are supported", opts.availability) + return fmt.Errorf("invalid availability %q, only active, pause and drain are supported", opts.availability) } } @@ -112,7 +113,7 @@ func runInit(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet, o if req.AutoLockManagers { unlockKeyResp, err := client.SwarmGetUnlockKey(ctx) if err != nil { - return errors.Wrap(err, "could not fetch unlock key") + return fmt.Errorf("could not fetch unlock key: %w", err) } printUnlockCommand(dockerCli.Out(), unlockKeyResp.UnlockKey) } diff --git a/cli/command/swarm/init_test.go b/cli/command/swarm/init_test.go index fbed83bde8..3dfb382d4c 100644 --- a/cli/command/swarm/init_test.go +++ b/cli/command/swarm/init_test.go @@ -8,7 +8,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -26,28 +26,28 @@ func TestSwarmInitErrorOnAPIFailure(t *testing.T) { { name: "init-failed", swarmInitFunc: func() (string, error) { - return "", errors.Errorf("error initializing the swarm") + return "", fmt.Errorf("error initializing the swarm") }, expectedError: "error initializing the swarm", }, { name: "init-failed-with-ip-choice", swarmInitFunc: func() (string, error) { - return "", errors.Errorf("could not choose an IP address to advertise") + return "", fmt.Errorf("could not choose an IP address to advertise") }, expectedError: "could not choose an IP address to advertise - specify one with --advertise-addr", }, { name: "swarm-inspect-after-init-failed", swarmInspectFunc: func() (swarm.Swarm, error) { - return swarm.Swarm{}, errors.Errorf("error inspecting the swarm") + return swarm.Swarm{}, fmt.Errorf("error inspecting the swarm") }, expectedError: "error inspecting the swarm", }, { name: "node-inspect-after-init-failed", nodeInspectFunc: func() (swarm.Node, []byte, error) { - return swarm.Node{}, []byte{}, errors.Errorf("error inspecting the node") + return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting the node") }, expectedError: "error inspecting the node", }, @@ -57,7 +57,7 @@ func TestSwarmInitErrorOnAPIFailure(t *testing.T) { flagAutolock: "true", }, swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) { - return types.SwarmUnlockKeyResponse{}, errors.Errorf("error getting swarm unlock key") + return types.SwarmUnlockKeyResponse{}, fmt.Errorf("error getting swarm unlock key") }, expectedError: "could not fetch unlock key: error getting swarm unlock key", }, diff --git a/cli/command/swarm/join.go b/cli/command/swarm/join.go index 3e497e7f1f..7b7cb61f18 100644 --- a/cli/command/swarm/join.go +++ b/cli/command/swarm/join.go @@ -8,7 +8,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -68,7 +68,7 @@ func runJoin(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet, o case swarm.NodeAvailabilityActive, swarm.NodeAvailabilityPause, swarm.NodeAvailabilityDrain: req.Availability = availability default: - return errors.Errorf("invalid availability %q, only active, pause and drain are supported", opts.availability) + return fmt.Errorf("invalid availability %q, only active, pause and drain are supported", opts.availability) } } diff --git a/cli/command/swarm/join_test.go b/cli/command/swarm/join_test.go index 6d60d693d2..4fd51fbfea 100644 --- a/cli/command/swarm/join_test.go +++ b/cli/command/swarm/join_test.go @@ -1,6 +1,7 @@ package swarm import ( + "fmt" "io" "strings" "testing" @@ -8,7 +9,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/system" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -34,7 +35,7 @@ func TestSwarmJoinErrors(t *testing.T) { name: "join-failed", args: []string{"remote"}, swarmJoinFunc: func() error { - return errors.Errorf("error joining the swarm") + return fmt.Errorf("error joining the swarm") }, expectedError: "error joining the swarm", }, @@ -42,7 +43,7 @@ func TestSwarmJoinErrors(t *testing.T) { name: "join-failed-on-init", args: []string{"remote"}, infoFunc: func() (system.Info, error) { - return system.Info{}, errors.Errorf("error asking for node info") + return system.Info{}, fmt.Errorf("error asking for node info") }, expectedError: "error asking for node info", }, diff --git a/cli/command/swarm/join_token.go b/cli/command/swarm/join_token.go index de0611700a..d66e40918e 100644 --- a/cli/command/swarm/join_token.go +++ b/cli/command/swarm/join_token.go @@ -2,12 +2,13 @@ package swarm import ( "context" + "errors" "fmt" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/swarm/join_token_test.go b/cli/command/swarm/join_token_test.go index c97cc0012d..5b1402bcfb 100644 --- a/cli/command/swarm/join_token_test.go +++ b/cli/command/swarm/join_token_test.go @@ -9,7 +9,7 @@ import ( "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/system" - "github.com/pkg/errors" + "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -43,7 +43,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) { name: "swarm-inspect-failed", args: []string{"worker"}, swarmInspectFunc: func() (swarm.Swarm, error) { - return swarm.Swarm{}, errors.Errorf("error inspecting the swarm") + return swarm.Swarm{}, fmt.Errorf("error inspecting the swarm") }, expectedError: "error inspecting the swarm", }, @@ -54,7 +54,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) { flagRotate: "true", }, swarmInspectFunc: func() (swarm.Swarm, error) { - return swarm.Swarm{}, errors.Errorf("error inspecting the swarm") + return swarm.Swarm{}, fmt.Errorf("error inspecting the swarm") }, expectedError: "error inspecting the swarm", }, @@ -65,7 +65,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) { flagRotate: "true", }, swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error { - return errors.Errorf("error updating the swarm") + return fmt.Errorf("error updating the swarm") }, expectedError: "error updating the swarm", }, @@ -73,7 +73,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) { name: "node-inspect-failed", args: []string{"worker"}, nodeInspectFunc: func() (swarm.Node, []byte, error) { - return swarm.Node{}, []byte{}, errors.Errorf("error inspecting node") + return swarm.Node{}, []byte{}, fmt.Errorf("error inspecting node") }, expectedError: "error inspecting node", }, @@ -81,7 +81,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) { name: "info-failed", args: []string{"worker"}, infoFunc: func() (system.Info, error) { - return system.Info{}, errors.Errorf("error asking for node info") + return system.Info{}, fmt.Errorf("error asking for node info") }, expectedError: "error asking for node info", }, diff --git a/cli/command/swarm/leave_test.go b/cli/command/swarm/leave_test.go index 58192e5ab4..65e5fe3256 100644 --- a/cli/command/swarm/leave_test.go +++ b/cli/command/swarm/leave_test.go @@ -1,12 +1,13 @@ package swarm import ( + "fmt" "io" "strings" "testing" "github.com/docker/cli/internal/test" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -26,7 +27,7 @@ func TestSwarmLeaveErrors(t *testing.T) { { name: "leave-failed", swarmLeaveFunc: func() error { - return errors.Errorf("error leaving the swarm") + return fmt.Errorf("error leaving the swarm") }, expectedError: "error leaving the swarm", }, diff --git a/cli/command/swarm/opts.go b/cli/command/swarm/opts.go index f8ebc900e8..f128f20140 100644 --- a/cli/command/swarm/opts.go +++ b/cli/command/swarm/opts.go @@ -3,6 +3,7 @@ package swarm import ( "encoding/csv" "encoding/pem" + "errors" "fmt" "os" "strings" @@ -10,7 +11,7 @@ import ( "github.com/docker/cli/opts" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "github.com/spf13/pflag" ) @@ -177,7 +178,7 @@ func parseExternalCA(caSpec string) (*swarm.ExternalCA, error) { for _, field := range fields { key, value, ok := strings.Cut(field, "=") if !ok { - return nil, errors.Errorf("invalid field '%s' must be a key=value pair", field) + return nil, fmt.Errorf("invalid field '%s' must be a key=value pair", field) } // TODO(thaJeztah): these options should not be case-insensitive. @@ -187,7 +188,7 @@ func parseExternalCA(caSpec string) (*swarm.ExternalCA, error) { if strings.ToLower(value) == string(swarm.ExternalCAProtocolCFSSL) { externalCA.Protocol = swarm.ExternalCAProtocolCFSSL } else { - return nil, errors.Errorf("unrecognized external CA protocol %s", value) + return nil, fmt.Errorf("unrecognized external CA protocol %s", value) } case "url": hasURL = true @@ -195,7 +196,7 @@ func parseExternalCA(caSpec string) (*swarm.ExternalCA, error) { case "cacert": cacontents, err := os.ReadFile(value) if err != nil { - return nil, errors.Wrap(err, "unable to read CA cert for external CA") + return nil, fmt.Errorf("unable to read CA cert for external CA: %w", err) } if pemBlock, _ := pem.Decode(cacontents); pemBlock == nil { return nil, errors.New("CA cert for external CA must be in PEM format") diff --git a/cli/command/swarm/unlock.go b/cli/command/swarm/unlock.go index 66ae6d5371..1cbb8b8056 100644 --- a/cli/command/swarm/unlock.go +++ b/cli/command/swarm/unlock.go @@ -3,6 +3,7 @@ package swarm import ( "bufio" "context" + "errors" "fmt" "io" "strings" @@ -12,7 +13,7 @@ import ( "github.com/docker/cli/cli/command/completion" "github.com/docker/cli/cli/streams" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "github.com/spf13/cobra" "golang.org/x/term" ) diff --git a/cli/command/swarm/unlock_key.go b/cli/command/swarm/unlock_key.go index 7caee23728..b024f5a0cb 100644 --- a/cli/command/swarm/unlock_key.go +++ b/cli/command/swarm/unlock_key.go @@ -2,6 +2,7 @@ package swarm import ( "context" + "errors" "fmt" "io" @@ -9,7 +10,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -68,7 +69,7 @@ func runUnlockKey(ctx context.Context, dockerCli command.Cli, opts unlockKeyOpti unlockKeyResp, err := client.SwarmGetUnlockKey(ctx) if err != nil { - return errors.Wrap(err, "could not fetch unlock key") + return fmt.Errorf("could not fetch unlock key: %w", err) } if unlockKeyResp.UnlockKey == "" { diff --git a/cli/command/swarm/unlock_key_test.go b/cli/command/swarm/unlock_key_test.go index 15d7f2e840..9b9f9eaaed 100644 --- a/cli/command/swarm/unlock_key_test.go +++ b/cli/command/swarm/unlock_key_test.go @@ -9,7 +9,7 @@ import ( "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -35,7 +35,7 @@ func TestSwarmUnlockKeyErrors(t *testing.T) { flagRotate: "true", }, swarmInspectFunc: func() (swarm.Swarm, error) { - return swarm.Swarm{}, errors.Errorf("error inspecting the swarm") + return swarm.Swarm{}, fmt.Errorf("error inspecting the swarm") }, expectedError: "error inspecting the swarm", }, @@ -58,14 +58,14 @@ func TestSwarmUnlockKeyErrors(t *testing.T) { return *builders.Swarm(builders.Autolock()), nil }, swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error { - return errors.Errorf("error updating the swarm") + return fmt.Errorf("error updating the swarm") }, expectedError: "error updating the swarm", }, { name: "swarm-get-unlock-key-failed", swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) { - return types.SwarmUnlockKeyResponse{}, errors.Errorf("error getting unlock key") + return types.SwarmUnlockKeyResponse{}, fmt.Errorf("error getting unlock key") }, expectedError: "error getting unlock key", }, diff --git a/cli/command/swarm/unlock_test.go b/cli/command/swarm/unlock_test.go index 04a996acb5..8ffec95606 100644 --- a/cli/command/swarm/unlock_test.go +++ b/cli/command/swarm/unlock_test.go @@ -1,6 +1,7 @@ package swarm import ( + "fmt" "io" "strings" "testing" @@ -9,7 +10,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/system" - "github.com/pkg/errors" + "gotest.tools/v3/assert" ) @@ -58,7 +59,7 @@ func TestSwarmUnlockErrors(t *testing.T) { }, nil }, swarmUnlockFunc: func(req swarm.UnlockRequest) error { - return errors.Errorf("error unlocking the swarm") + return fmt.Errorf("error unlocking the swarm") }, expectedError: "error unlocking the swarm", }, @@ -91,7 +92,7 @@ func TestSwarmUnlock(t *testing.T) { }, swarmUnlockFunc: func(req swarm.UnlockRequest) error { if req.UnlockKey != input { - return errors.Errorf("Invalid unlock key") + return fmt.Errorf("Invalid unlock key") } return nil }, diff --git a/cli/command/swarm/update.go b/cli/command/swarm/update.go index 50ddc17b1a..e3855409dc 100644 --- a/cli/command/swarm/update.go +++ b/cli/command/swarm/update.go @@ -8,7 +8,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -67,7 +67,7 @@ func runUpdate(ctx context.Context, dockerCli command.Cli, flags *pflag.FlagSet, if curAutoLock && !prevAutoLock { unlockKeyResp, err := client.SwarmGetUnlockKey(ctx) if err != nil { - return errors.Wrap(err, "could not fetch unlock key") + return fmt.Errorf("could not fetch unlock key: %w", err) } printUnlockCommand(dockerCli.Out(), unlockKeyResp.UnlockKey) } diff --git a/cli/command/swarm/update_test.go b/cli/command/swarm/update_test.go index debab12d21..591ab7ade8 100644 --- a/cli/command/swarm/update_test.go +++ b/cli/command/swarm/update_test.go @@ -10,7 +10,7 @@ import ( "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" - "github.com/pkg/errors" + "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -36,7 +36,7 @@ func TestSwarmUpdateErrors(t *testing.T) { flagTaskHistoryLimit: "10", }, swarmInspectFunc: func() (swarm.Swarm, error) { - return swarm.Swarm{}, errors.Errorf("error inspecting the swarm") + return swarm.Swarm{}, fmt.Errorf("error inspecting the swarm") }, expectedError: "error inspecting the swarm", }, @@ -46,7 +46,7 @@ func TestSwarmUpdateErrors(t *testing.T) { flagTaskHistoryLimit: "10", }, swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error { - return errors.Errorf("error updating the swarm") + return fmt.Errorf("error updating the swarm") }, expectedError: "error updating the swarm", }, @@ -59,7 +59,7 @@ func TestSwarmUpdateErrors(t *testing.T) { return *builders.Swarm(), nil }, swarmGetUnlockKeyFunc: func() (types.SwarmUnlockKeyResponse, error) { - return types.SwarmUnlockKeyResponse{}, errors.Errorf("error getting unlock key") + return types.SwarmUnlockKeyResponse{}, fmt.Errorf("error getting unlock key") }, expectedError: "error getting unlock key", }, @@ -115,33 +115,33 @@ func TestSwarmUpdate(t *testing.T) { }, swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error { if *swarm.Orchestration.TaskHistoryRetentionLimit != 10 { - return errors.Errorf("historyLimit not correctly set") + return fmt.Errorf("historyLimit not correctly set") } heartbeatDuration, err := time.ParseDuration("10s") if err != nil { return err } if swarm.Dispatcher.HeartbeatPeriod != heartbeatDuration { - return errors.Errorf("heartbeatPeriodLimit not correctly set") + return fmt.Errorf("heartbeatPeriodLimit not correctly set") } certExpiryDuration, err := time.ParseDuration("20s") if err != nil { return err } if swarm.CAConfig.NodeCertExpiry != certExpiryDuration { - return errors.Errorf("certExpiry not correctly set") + return fmt.Errorf("certExpiry not correctly set") } if len(swarm.CAConfig.ExternalCAs) != 1 || swarm.CAConfig.ExternalCAs[0].CACert != "trustroot" { - return errors.Errorf("externalCA not correctly set") + return fmt.Errorf("externalCA not correctly set") } if *swarm.Raft.KeepOldSnapshots != 10 { - return errors.Errorf("keepOldSnapshots not correctly set") + return fmt.Errorf("keepOldSnapshots not correctly set") } if swarm.Raft.SnapshotInterval != 100 { - return errors.Errorf("snapshotInterval not correctly set") + return fmt.Errorf("snapshotInterval not correctly set") } if !swarm.EncryptionConfig.AutoLockManagers { - return errors.Errorf("autolock not correctly set") + return fmt.Errorf("autolock not correctly set") } return nil }, @@ -154,7 +154,7 @@ func TestSwarmUpdate(t *testing.T) { }, swarmUpdateFunc: func(swarm swarm.Spec, flags swarm.UpdateFlags) error { if *swarm.Orchestration.TaskHistoryRetentionLimit != 10 { - return errors.Errorf("historyLimit not correctly set") + return fmt.Errorf("historyLimit not correctly set") } return nil }, diff --git a/cli/command/system/dial_stdio.go b/cli/command/system/dial_stdio.go index d4193ce8af..9d1f25cf23 100644 --- a/cli/command/system/dial_stdio.go +++ b/cli/command/system/dial_stdio.go @@ -2,13 +2,15 @@ package system import ( "context" + "errors" + "fmt" "io" "os" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" - "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -35,7 +37,7 @@ func runDialStdio(ctx context.Context, dockerCli command.Cli) error { dialer := dockerCli.Client().Dialer() conn, err := dialer(ctx) if err != nil { - return errors.Wrap(err, "failed to open the raw stream connection") + return fmt.Errorf("failed to open the raw stream connection: %w", err) } defer conn.Close() @@ -81,7 +83,7 @@ func copier(to halfWriteCloser, from halfReadCloser, debugDescription string) er } }() if _, err := io.Copy(to, from); err != nil { - return errors.Wrapf(err, "error while Copy (%s)", debugDescription) + return fmt.Errorf("error while Copy (%s): %w", debugDescription, err) } return nil } diff --git a/cli/command/system/inspect.go b/cli/command/system/inspect.go index d4aed789b1..08457d28cc 100644 --- a/cli/command/system/inspect.go +++ b/cli/command/system/inspect.go @@ -15,7 +15,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/network" "github.com/docker/docker/errdefs" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -54,7 +54,7 @@ func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions) case "", "container", "image", "node", "network", "service", "volume", "task", "plugin", "secret": elementSearcher = inspectAll(ctx, dockerCli, opts.size, opts.inspectType) default: - return errors.Errorf("%q is not a valid value for --type", opts.inspectType) + return fmt.Errorf("%q is not a valid value for --type", opts.inspectType) } return inspect.Inspect(dockerCli.Out(), opts.ids, opts.format, elementSearcher) } @@ -212,7 +212,7 @@ func inspectAll(ctx context.Context, dockerCli command.Cli, getSize bool, typeCo } return v, raw, err } - return nil, nil, errors.Errorf("Error: No such object: %s", ref) + return nil, nil, fmt.Errorf("Error: No such object: %s", ref) } } diff --git a/cli/command/system/prune.go b/cli/command/system/prune.go index 815efdef76..33a944ba56 100644 --- a/cli/command/system/prune.go +++ b/cli/command/system/prune.go @@ -3,6 +3,7 @@ package system import ( "bytes" "context" + "errors" "fmt" "sort" "text/template" @@ -20,7 +21,7 @@ import ( "github.com/docker/docker/errdefs" "github.com/docker/go-units" "github.com/fvbommel/sortorder" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/system/prune_test.go b/cli/command/system/prune_test.go index fa7294467f..accbdeb2bc 100644 --- a/cli/command/system/prune_test.go +++ b/cli/command/system/prune_test.go @@ -2,6 +2,7 @@ package system import ( "context" + "errors" "io" "testing" @@ -10,7 +11,7 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/network" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) diff --git a/cli/command/telemetry_docker.go b/cli/command/telemetry_docker.go index c3612a7e0c..d2256c654c 100644 --- a/cli/command/telemetry_docker.go +++ b/cli/command/telemetry_docker.go @@ -14,7 +14,6 @@ import ( "strings" "unicode" - "github.com/pkg/errors" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc" "go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc" @@ -48,7 +47,7 @@ func dockerExporterOTLPEndpoint(cli Cli) (endpoint string, secure bool) { if otelCfg != nil { otelMap, ok := otelCfg.(map[string]any) if !ok { - otel.Handle(errors.Errorf( + otel.Handle(fmt.Errorf( "unexpected type for field %q: %T (expected: %T)", otelContextFieldName, otelCfg, @@ -76,7 +75,7 @@ func dockerExporterOTLPEndpoint(cli Cli) (endpoint string, secure bool) { // We pretend we're the same as the environment reader. u, err := url.Parse(endpoint) if err != nil { - otel.Handle(errors.Errorf("docker otel endpoint is invalid: %s", err)) + otel.Handle(fmt.Errorf("docker otel endpoint is invalid: %s", err)) return "", false } diff --git a/cli/command/telemetry_utils.go b/cli/command/telemetry_utils.go index 680415b637..d62201a9bf 100644 --- a/cli/command/telemetry_utils.go +++ b/cli/command/telemetry_utils.go @@ -2,12 +2,13 @@ package command import ( "context" + "errors" "fmt" "strings" "time" "github.com/docker/cli/cli/version" - "github.com/pkg/errors" + "github.com/spf13/cobra" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" diff --git a/cli/command/trust/key_generate.go b/cli/command/trust/key_generate.go index 39eb0cb1b9..72dba180bd 100644 --- a/cli/command/trust/key_generate.go +++ b/cli/command/trust/key_generate.go @@ -11,7 +11,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/trust" - "github.com/pkg/errors" + "github.com/spf13/cobra" "github.com/theupdateframework/notary" "github.com/theupdateframework/notary/trustmanager" @@ -88,7 +88,7 @@ func validateAndGenerateKey(streams command.Streams, keyName string, workingDir pubPEM, err := generateKeyAndOutputPubPEM(keyName, privKeyFileStore) if err != nil { fmt.Fprint(streams.Out(), err.Error()) - return errors.Wrapf(err, "failed to generate key for %s", keyName) + return fmt.Errorf("failed to generate key for %s: %w", keyName, err) } // Output the public key to a file in the CWD or specified dir @@ -126,7 +126,7 @@ func writePubKeyPEMToDir(pubPEM pem.Block, keyName, workingDir string) (string, pubFileName := strings.Join([]string{keyName, "pub"}, ".") pubFilePath := filepath.Join(workingDir, pubFileName) if err := os.WriteFile(pubFilePath, pem.EncodeToMemory(&pubPEM), notary.PrivNoExecPerms); err != nil { - return "", errors.Wrapf(err, "failed to write public key to %s", pubFilePath) + return "", fmt.Errorf("failed to write public key to %s: %w", pubFilePath, err) } return pubFilePath, nil } diff --git a/cli/command/trust/key_load.go b/cli/command/trust/key_load.go index 4a5bb26055..80f778d7b2 100644 --- a/cli/command/trust/key_load.go +++ b/cli/command/trust/key_load.go @@ -3,6 +3,7 @@ package trust import ( "bytes" "encoding/pem" + "errors" "fmt" "io" "os" @@ -11,7 +12,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/trust" - "github.com/pkg/errors" + "github.com/spf13/cobra" "github.com/theupdateframework/notary" "github.com/theupdateframework/notary/storage" @@ -60,10 +61,10 @@ func loadPrivKey(streams command.Streams, keyPath string, options keyLoadOptions passRet := trust.GetPassphraseRetriever(streams.In(), streams.Out()) keyBytes, err := getPrivKeyBytesFromPath(keyPath) if err != nil { - return errors.Wrapf(err, "refusing to load key from %s", keyPath) + return fmt.Errorf("refusing to load key from %s: %w", keyPath, err) } if err := loadPrivKeyBytesToStore(keyBytes, privKeyImporters, keyPath, options.keyName, passRet); err != nil { - return errors.Wrapf(err, "error importing key from %s", keyPath) + return fmt.Errorf("error importing key from %s: %w", keyPath, err) } fmt.Fprintf(streams.Out(), "Successfully imported key from %s\n", keyPath) return nil @@ -95,7 +96,7 @@ func loadPrivKeyBytesToStore(privKeyBytes []byte, privKeyImporters []trustmanage return fmt.Errorf("provided file %s is not a supported private key - to add a signer's public key use docker trust signer add", keyPath) } if privKeyBytes, err = decodePrivKeyIfNecessary(privKeyBytes, passRet); err != nil { - return errors.Wrapf(err, "cannot load key from provided file %s", keyPath) + return fmt.Errorf("cannot load key from provided file %s: %w", keyPath, err) } // Make a reader, rewind the file pointer return trustmanager.ImportKeys(bytes.NewReader(privKeyBytes), privKeyImporters, keyName, "", passRet) diff --git a/cli/command/trust/revoke.go b/cli/command/trust/revoke.go index a30d6cccc6..3957c8a2fa 100644 --- a/cli/command/trust/revoke.go +++ b/cli/command/trust/revoke.go @@ -2,6 +2,7 @@ package trust import ( "context" + "errors" "fmt" "github.com/docker/cli/cli" @@ -9,7 +10,7 @@ import ( "github.com/docker/cli/cli/command/image" "github.com/docker/cli/cli/trust" "github.com/docker/docker/errdefs" - "github.com/pkg/errors" + "github.com/spf13/cobra" "github.com/theupdateframework/notary/client" "github.com/theupdateframework/notary/tuf/data" @@ -63,7 +64,7 @@ func revokeTrust(ctx context.Context, dockerCLI command.Cli, remote string, opti } defer clearChangeList(notaryRepo) if err := revokeSignature(notaryRepo, tag); err != nil { - return errors.Wrapf(err, "could not remove signature for %s", remote) + return fmt.Errorf("could not remove signature for %s: %w", remote, err) } _, _ = fmt.Fprintf(dockerCLI.Out(), "Successfully deleted signature for %s\n", remote) return nil diff --git a/cli/command/trust/sign.go b/cli/command/trust/sign.go index 87fce71004..69d05d0084 100644 --- a/cli/command/trust/sign.go +++ b/cli/command/trust/sign.go @@ -2,6 +2,7 @@ package trust import ( "context" + "errors" "fmt" "io" "path" @@ -15,7 +16,7 @@ import ( imagetypes "github.com/docker/docker/api/types/image" registrytypes "github.com/docker/docker/api/types/registry" "github.com/docker/docker/client" - "github.com/pkg/errors" + "github.com/spf13/cobra" notaryclient "github.com/theupdateframework/notary/client" "github.com/theupdateframework/notary/tuf/data" @@ -123,7 +124,7 @@ func signAndPublishToTarget(out io.Writer, imgRefAndAuth trust.ImageRefAndAuth, err = notaryRepo.Publish() } if err != nil { - return errors.Wrapf(err, "failed to sign %s:%s", imgRefAndAuth.RepoInfo().Name.Name(), tag) + return fmt.Errorf("failed to sign %s:%s: %w", imgRefAndAuth.RepoInfo().Name.Name(), tag, err) } fmt.Fprintf(out, "Successfully signed %s:%s\n", imgRefAndAuth.RepoInfo().Name.Name(), tag) return nil @@ -208,7 +209,7 @@ func initNotaryRepoWithSigners(notaryRepo notaryclient.Repository, newSigner dat return err } if err := addStagedSigner(notaryRepo, newSigner, []data.PublicKey{signerKey}); err != nil { - return errors.Wrapf(err, "could not add signer to repo: %s", strings.TrimPrefix(newSigner.String(), "targets/")) + return fmt.Errorf("could not add signer to repo: %s: %w", strings.TrimPrefix(newSigner.String(), "targets/"), err) } return notaryRepo.Publish() diff --git a/cli/command/trust/signer_add.go b/cli/command/trust/signer_add.go index 28e63cf1ec..06e4195f7c 100644 --- a/cli/command/trust/signer_add.go +++ b/cli/command/trust/signer_add.go @@ -2,6 +2,7 @@ package trust import ( "context" + "errors" "fmt" "io" "os" @@ -14,7 +15,7 @@ import ( "github.com/docker/cli/cli/command/image" "github.com/docker/cli/cli/trust" "github.com/docker/cli/opts" - "github.com/pkg/errors" + "github.com/spf13/cobra" "github.com/theupdateframework/notary/client" "github.com/theupdateframework/notary/tuf/data" @@ -106,7 +107,7 @@ func addSignerToRepo(ctx context.Context, dockerCLI command.Cli, signerName stri newSignerRoleName := data.RoleName(path.Join(data.CanonicalTargetsRole.String(), signerName)) if err := addStagedSigner(notaryRepo, newSignerRoleName, signerPubKeys); err != nil { - return errors.Wrapf(err, "could not add signer to repo: %s", strings.TrimPrefix(newSignerRoleName.String(), "targets/")) + return fmt.Errorf("could not add signer to repo: %s: %w", strings.TrimPrefix(newSignerRoleName.String(), "targets/"), err) } return notaryRepo.Publish() @@ -118,20 +119,20 @@ func ingestPublicKeys(pubKeyPaths []string) ([]data.PublicKey, error) { // Read public key bytes from PEM file, limit to 1 KiB pubKeyFile, err := os.OpenFile(pubKeyPath, os.O_RDONLY, 0o666) if err != nil { - return nil, errors.Wrap(err, "unable to read public key from file") + return nil, fmt.Errorf("unable to read public key from file: %w", err) } defer pubKeyFile.Close() // limit to l := io.LimitReader(pubKeyFile, 1<<20) pubKeyBytes, err := io.ReadAll(l) if err != nil { - return nil, errors.Wrap(err, "unable to read public key from file") + return nil, fmt.Errorf("unable to read public key from file: %w", err) } // Parse PEM bytes into type PublicKey pubKey, err := tufutils.ParsePEMPublicKey(pubKeyBytes) if err != nil { - return nil, errors.Wrapf(err, "could not parse public key from file: %s", pubKeyPath) + return nil, fmt.Errorf("could not parse public key from file: %s: %w", pubKeyPath, err) } pubKeys = append(pubKeys, pubKey) } diff --git a/cli/command/trust/signer_remove.go b/cli/command/trust/signer_remove.go index 1c85fcd9fd..208af5b1dd 100644 --- a/cli/command/trust/signer_remove.go +++ b/cli/command/trust/signer_remove.go @@ -2,6 +2,7 @@ package trust import ( "context" + "errors" "fmt" "strings" @@ -9,7 +10,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/image" "github.com/docker/cli/cli/trust" - "github.com/pkg/errors" + "github.com/spf13/cobra" "github.com/theupdateframework/notary/client" "github.com/theupdateframework/notary/tuf/data" @@ -48,7 +49,7 @@ func removeSigner(ctx context.Context, dockerCLI command.Cli, options signerRemo } } if len(errRepos) > 0 { - return errors.Errorf("error removing signer from: %s", strings.Join(errRepos, ", ")) + return fmt.Errorf("error removing signer from: %s", strings.Join(errRepos, ", ")) } return nil } @@ -101,7 +102,7 @@ func removeSingleSigner(ctx context.Context, dockerCLI command.Cli, repoName, si signerDelegation := data.RoleName("targets/" + signerName) if signerDelegation == releasesRoleTUFName { - return false, errors.Errorf("releases is a reserved keyword and cannot be removed") + return false, fmt.Errorf("releases is a reserved keyword and cannot be removed") } notaryRepo, err := dockerCLI.NotaryClient(imgRefAndAuth, trust.ActionsPushAndPull) if err != nil { @@ -109,7 +110,7 @@ func removeSingleSigner(ctx context.Context, dockerCLI command.Cli, repoName, si } delegationRoles, err := notaryRepo.GetDelegationRoles() if err != nil { - return false, errors.Wrapf(err, "error retrieving signers for %s", repoName) + return false, fmt.Errorf("error retrieving signers for %s: %w", repoName, err) } var role data.Role for _, delRole := range delegationRoles { @@ -119,7 +120,7 @@ func removeSingleSigner(ctx context.Context, dockerCLI command.Cli, repoName, si } } if role.Name == "" { - return false, errors.Errorf("no signer %s for repository %s", signerName, repoName) + return false, fmt.Errorf("no signer %s for repository %s", signerName, repoName) } allRoles, err := notaryRepo.ListRoles() if err != nil { diff --git a/cli/command/utils.go b/cli/command/utils.go index 1cf4d199de..91f88e3410 100644 --- a/cli/command/utils.go +++ b/cli/command/utils.go @@ -6,6 +6,7 @@ package command import ( "bufio" "context" + "errors" "fmt" "io" "os" @@ -20,7 +21,7 @@ import ( "github.com/docker/docker/errdefs" "github.com/moby/sys/sequential" "github.com/moby/term" - "github.com/pkg/errors" + "github.com/spf13/pflag" ) @@ -207,7 +208,7 @@ func ValidateOutputPath(path string) error { dir := filepath.Dir(filepath.Clean(path)) if dir != "" && dir != "." { if _, err := os.Stat(dir); os.IsNotExist(err) { - return errors.Errorf("invalid output path: directory %q does not exist", dir) + return fmt.Errorf("invalid output path: directory %q does not exist", dir) } } // check whether `path` points to a regular file @@ -222,7 +223,7 @@ func ValidateOutputPath(path string) error { } if err := ValidateOutputPathFileMode(fileInfo.Mode()); err != nil { - return errors.Wrapf(err, "invalid output path: %q must be a directory or a regular file", path) + return fmt.Errorf("invalid output path: %q must be a directory or a regular file: %w", path, err) } } return nil @@ -275,11 +276,11 @@ func StringSliceReplaceAt(s, find, replace []string, requireIndex int) ([]string func ValidateMountWithAPIVersion(m mounttypes.Mount, serverAPIVersion string) error { if m.BindOptions != nil { if m.BindOptions.NonRecursive && versions.LessThan(serverAPIVersion, "1.40") { - return errors.Errorf("bind-recursive=disabled requires API v1.40 or later") + return fmt.Errorf("bind-recursive=disabled requires API v1.40 or later") } // ReadOnlyNonRecursive can be safely ignored when API < 1.44 if m.BindOptions.ReadOnlyForceRecursive && versions.LessThan(serverAPIVersion, "1.44") { - return errors.Errorf("bind-recursive=readonly requires API v1.44 or later") + return fmt.Errorf("bind-recursive=readonly requires API v1.44 or later") } } return nil diff --git a/cli/command/utils_test.go b/cli/command/utils_test.go index 2f2140757e..cc9aea6146 100644 --- a/cli/command/utils_test.go +++ b/cli/command/utils_test.go @@ -4,6 +4,7 @@ import ( "bufio" "bytes" "context" + "errors" "fmt" "io" "os" @@ -17,7 +18,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/streams" "github.com/docker/cli/internal/test" - "github.com/pkg/errors" + "gotest.tools/v3/assert" ) diff --git a/cli/command/volume/create.go b/cli/command/volume/create.go index 0e4d035f9a..acda45471d 100644 --- a/cli/command/volume/create.go +++ b/cli/command/volume/create.go @@ -11,7 +11,7 @@ import ( "github.com/docker/cli/cli/command/completion" "github.com/docker/cli/opts" "github.com/docker/docker/api/types/volume" - "github.com/pkg/errors" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -52,7 +52,7 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { if len(args) == 1 { if options.name != "" { - return errors.Errorf("conflicting options: cannot specify a volume-name through both --name and as a positional arg") + return fmt.Errorf("conflicting options: cannot specify a volume-name through both --name and as a positional arg") } options.name = args[0] } diff --git a/cli/command/volume/create_test.go b/cli/command/volume/create_test.go index 3417fb689a..0e750d9d29 100644 --- a/cli/command/volume/create_test.go +++ b/cli/command/volume/create_test.go @@ -1,6 +1,8 @@ package volume import ( + "errors" + "fmt" "io" "reflect" "sort" @@ -9,7 +11,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/volume" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -34,7 +36,7 @@ func TestVolumeCreateErrors(t *testing.T) { }, { volumeCreateFunc: func(createBody volume.CreateOptions) (volume.Volume, error) { - return volume.Volume{}, errors.Errorf("error creating volume") + return volume.Volume{}, fmt.Errorf("error creating volume") }, expectedError: "error creating volume", }, @@ -60,7 +62,7 @@ func TestVolumeCreateWithName(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ volumeCreateFunc: func(body volume.CreateOptions) (volume.Volume, error) { if body.Name != name { - return volume.Volume{}, errors.Errorf("expected name %q, got %q", name, body.Name) + return volume.Volume{}, fmt.Errorf("expected name %q, got %q", name, body.Name) } return volume.Volume{ Name: body.Name, @@ -99,16 +101,16 @@ func TestVolumeCreateWithFlags(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ volumeCreateFunc: func(body volume.CreateOptions) (volume.Volume, error) { if body.Name != "" { - return volume.Volume{}, errors.Errorf("expected empty name, got %q", body.Name) + return volume.Volume{}, fmt.Errorf("expected empty name, got %q", body.Name) } if body.Driver != expectedDriver { - return volume.Volume{}, errors.Errorf("expected driver %q, got %q", expectedDriver, body.Driver) + return volume.Volume{}, fmt.Errorf("expected driver %q, got %q", expectedDriver, body.Driver) } if !reflect.DeepEqual(body.DriverOpts, expectedOpts) { - return volume.Volume{}, errors.Errorf("expected drivers opts %v, got %v", expectedOpts, body.DriverOpts) + return volume.Volume{}, fmt.Errorf("expected drivers opts %v, got %v", expectedOpts, body.DriverOpts) } if !reflect.DeepEqual(body.Labels, expectedLabels) { - return volume.Volume{}, errors.Errorf("expected labels %v, got %v", expectedLabels, body.Labels) + return volume.Volume{}, fmt.Errorf("expected labels %v, got %v", expectedLabels, body.Labels) } return volume.Volume{ Name: name, diff --git a/cli/command/volume/inspect_test.go b/cli/command/volume/inspect_test.go index 624dc8de63..6bf6a28af9 100644 --- a/cli/command/volume/inspect_test.go +++ b/cli/command/volume/inspect_test.go @@ -9,7 +9,7 @@ import ( "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/volume" - "github.com/pkg/errors" + "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -27,7 +27,7 @@ func TestVolumeInspectErrors(t *testing.T) { { args: []string{"foo"}, volumeInspectFunc: func(volumeID string) (volume.Volume, error) { - return volume.Volume{}, errors.Errorf("error while inspecting the volume") + return volume.Volume{}, fmt.Errorf("error while inspecting the volume") }, expectedError: "error while inspecting the volume", }, @@ -46,7 +46,7 @@ func TestVolumeInspectErrors(t *testing.T) { Name: "foo", }, nil } - return volume.Volume{}, errors.Errorf("error while inspecting the volume") + return volume.Volume{}, fmt.Errorf("error while inspecting the volume") }, expectedError: "error while inspecting the volume", }, @@ -78,7 +78,7 @@ func TestVolumeInspectWithoutFormat(t *testing.T) { args: []string{"foo"}, volumeInspectFunc: func(volumeID string) (volume.Volume, error) { if volumeID != "foo" { - return volume.Volume{}, errors.Errorf("Invalid volumeID, expected %s, got %s", "foo", volumeID) + return volume.Volume{}, fmt.Errorf("Invalid volumeID, expected %s, got %s", "foo", volumeID) } return *builders.Volume(), nil }, diff --git a/cli/command/volume/list_test.go b/cli/command/volume/list_test.go index 08fd403848..f51ece9c84 100644 --- a/cli/command/volume/list_test.go +++ b/cli/command/volume/list_test.go @@ -1,6 +1,7 @@ package volume import ( + "fmt" "io" "testing" @@ -9,7 +10,7 @@ import ( "github.com/docker/cli/internal/test/builders" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/volume" - "github.com/pkg/errors" + "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -27,7 +28,7 @@ func TestVolumeListErrors(t *testing.T) { }, { volumeListFunc: func(filter filters.Args) (volume.ListResponse, error) { - return volume.ListResponse{}, errors.Errorf("error listing volumes") + return volume.ListResponse{}, fmt.Errorf("error listing volumes") }, expectedError: "error listing volumes", }, diff --git a/cli/command/volume/prune.go b/cli/command/volume/prune.go index 9aa931186b..c3d3357cc7 100644 --- a/cli/command/volume/prune.go +++ b/cli/command/volume/prune.go @@ -2,6 +2,7 @@ package volume import ( "context" + "errors" "fmt" "github.com/docker/cli/cli" @@ -11,7 +12,7 @@ import ( "github.com/docker/docker/api/types/versions" "github.com/docker/docker/errdefs" units "github.com/docker/go-units" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) diff --git a/cli/command/volume/prune_test.go b/cli/command/volume/prune_test.go index 5cb1aca34a..e3c62b13d0 100644 --- a/cli/command/volume/prune_test.go +++ b/cli/command/volume/prune_test.go @@ -2,6 +2,7 @@ package volume import ( "context" + "errors" "fmt" "io" "runtime" @@ -12,7 +13,7 @@ import ( "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/volume" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" "gotest.tools/v3/golden" @@ -38,7 +39,7 @@ func TestVolumePruneErrors(t *testing.T) { "force": "true", }, volumePruneFunc: func(args filters.Args) (volume.PruneReport, error) { - return volume.PruneReport{}, errors.Errorf("error pruning volumes") + return volume.PruneReport{}, fmt.Errorf("error pruning volumes") }, expectedError: "error pruning volumes", }, diff --git a/cli/command/volume/remove.go b/cli/command/volume/remove.go index df3dfe79a0..a073e01482 100644 --- a/cli/command/volume/remove.go +++ b/cli/command/volume/remove.go @@ -8,7 +8,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -55,7 +55,7 @@ func runRemove(ctx context.Context, dockerCli command.Cli, opts *removeOptions) } if len(errs) > 0 { - return errors.Errorf("%s", strings.Join(errs, "\n")) + return fmt.Errorf("%s", strings.Join(errs, "\n")) } return nil } diff --git a/cli/command/volume/remove_test.go b/cli/command/volume/remove_test.go index 61ac03578b..c666e8f7aa 100644 --- a/cli/command/volume/remove_test.go +++ b/cli/command/volume/remove_test.go @@ -1,11 +1,12 @@ package volume import ( + "fmt" "io" "testing" "github.com/docker/cli/internal/test" - "github.com/pkg/errors" + "gotest.tools/v3/assert" ) @@ -21,7 +22,7 @@ func TestVolumeRemoveErrors(t *testing.T) { { args: []string{"nodeID"}, volumeRemoveFunc: func(volumeID string, force bool) error { - return errors.Errorf("error removing the volume") + return fmt.Errorf("error removing the volume") }, expectedError: "error removing the volume", }, diff --git a/cli/command/volume/update.go b/cli/command/volume/update.go index 42ce9ac586..d2748abe6a 100644 --- a/cli/command/volume/update.go +++ b/cli/command/volume/update.go @@ -2,12 +2,13 @@ package volume import ( "context" + "errors" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" "github.com/docker/docker/api/types/volume" - "github.com/pkg/errors" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) diff --git a/cli/compose/convert/service.go b/cli/compose/convert/service.go index 44b6de1415..08a8f1f9e0 100644 --- a/cli/compose/convert/service.go +++ b/cli/compose/convert/service.go @@ -2,6 +2,7 @@ package convert import ( "context" + "fmt" "os" "sort" "strings" @@ -14,7 +15,6 @@ import ( "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/versions" "github.com/docker/docker/client" - "github.com/pkg/errors" ) const ( @@ -34,16 +34,16 @@ func Services( for _, service := range config.Services { secrets, err := convertServiceSecrets(ctx, apiClient, namespace, service.Secrets, config.Secrets) if err != nil { - return nil, errors.Wrapf(err, "service %s", service.Name) + return nil, fmt.Errorf("service %s: %w", service.Name, err) } configs, err := convertServiceConfigObjs(ctx, apiClient, namespace, service, config.Configs) if err != nil { - return nil, errors.Wrapf(err, "service %s", service.Name) + return nil, fmt.Errorf("service %s: %w", service.Name, err) } serviceSpec, err := Service(apiClient.ClientVersion(), namespace, service, config.Networks, config.Volumes, secrets, configs) if err != nil { - return nil, errors.Wrapf(err, "service %s", service.Name) + return nil, fmt.Errorf("service %s: %w", service.Name, err) } result[service.Name] = serviceSpec } @@ -212,7 +212,7 @@ func convertServiceNetworks( for networkName, network := range networks { networkConfig, ok := networkConfigs[networkName] if !ok && networkName != defaultNetwork { - return nil, errors.Errorf("undefined network %q", networkName) + return nil, fmt.Errorf("undefined network %q", networkName) } var aliases []string var driverOpts map[string]string @@ -256,7 +256,7 @@ func convertServiceSecrets( lookup := func(key string) (composetypes.FileObjectConfig, error) { secretSpec, exists := secretSpecs[key] if !exists { - return composetypes.FileObjectConfig{}, errors.Errorf("undefined secret %q", key) + return composetypes.FileObjectConfig{}, fmt.Errorf("undefined secret %q", key) } return composetypes.FileObjectConfig(secretSpec), nil } @@ -301,7 +301,7 @@ func convertServiceConfigObjs( lookup := func(key string) (composetypes.FileObjectConfig, error) { configSpec, exists := configSpecs[key] if !exists { - return composetypes.FileObjectConfig{}, errors.Errorf("undefined config %q", key) + return composetypes.FileObjectConfig{}, fmt.Errorf("undefined config %q", key) } return composetypes.FileObjectConfig(configSpec), nil } @@ -442,7 +442,7 @@ func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container ) if healthcheck.Disable { if len(healthcheck.Test) != 0 { - return nil, errors.Errorf("test and disable can't be set at the same time") + return nil, fmt.Errorf("test and disable can't be set at the same time") } return &container.HealthConfig{ Test: []string{"NONE"}, @@ -494,7 +494,7 @@ func convertRestartPolicy(restart string, source *composetypes.RestartPolicy) (* MaxAttempts: &attempts, }, nil default: - return nil, errors.Errorf("unknown restart policy: %s", restart) + return nil, fmt.Errorf("unknown restart policy: %s", restart) } } @@ -618,12 +618,12 @@ func convertDeployMode(mode string, replicas *uint64) (swarm.ServiceMode, error) switch mode { case "global-job": if replicas != nil { - return serviceMode, errors.Errorf("replicas can only be used with replicated or replicated-job mode") + return serviceMode, fmt.Errorf("replicas can only be used with replicated or replicated-job mode") } serviceMode.GlobalJob = &swarm.GlobalJob{} case "global": if replicas != nil { - return serviceMode, errors.Errorf("replicas can only be used with replicated or replicated-job mode") + return serviceMode, fmt.Errorf("replicas can only be used with replicated or replicated-job mode") } serviceMode.Global = &swarm.GlobalService{} case "replicated-job": @@ -634,7 +634,7 @@ func convertDeployMode(mode string, replicas *uint64) (swarm.ServiceMode, error) case "replicated", "": serviceMode.Replicated = &swarm.ReplicatedService{Replicas: replicas} default: - return serviceMode, errors.Errorf("Unknown mode: %s", mode) + return serviceMode, fmt.Errorf("Unknown mode: %s", mode) } return serviceMode, nil } @@ -667,9 +667,9 @@ func convertCredentialSpec(namespace Namespace, spec composetypes.CredentialSpec case l == 0: return nil, nil case l == 2: - return nil, errors.Errorf("invalid credential spec: cannot specify both %s and %s", o[0], o[1]) + return nil, fmt.Errorf("invalid credential spec: cannot specify both %s and %s", o[0], o[1]) case l > 2: - return nil, errors.Errorf("invalid credential spec: cannot specify both %s, and %s", strings.Join(o[:l-1], ", "), o[l-1]) + return nil, fmt.Errorf("invalid credential spec: cannot specify both %s, and %s", strings.Join(o[:l-1], ", "), o[l-1]) } swarmCredSpec := swarm.CredentialSpec(spec) // if we're using a swarm Config for the credential spec, over-write it @@ -688,7 +688,7 @@ func convertCredentialSpec(namespace Namespace, spec composetypes.CredentialSpec return &swarmCredSpec, nil } } - return nil, errors.Errorf("invalid credential spec: spec specifies config %v, but no such config can be found", swarmCredSpec.Config) + return nil, fmt.Errorf("invalid credential spec: spec specifies config %v, but no such config can be found", swarmCredSpec.Config) } return &swarmCredSpec, nil } diff --git a/cli/compose/convert/service_test.go b/cli/compose/convert/service_test.go index 22f585f87c..5156ecd49b 100644 --- a/cli/compose/convert/service_test.go +++ b/cli/compose/convert/service_test.go @@ -2,6 +2,7 @@ package convert import ( "context" + "errors" "os" "strings" "testing" @@ -12,7 +13,7 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) diff --git a/cli/compose/convert/volume.go b/cli/compose/convert/volume.go index 387362203f..51565578d6 100644 --- a/cli/compose/convert/volume.go +++ b/cli/compose/convert/volume.go @@ -1,11 +1,12 @@ package convert import ( + "errors" + "fmt" "strings" composetypes "github.com/docker/cli/cli/compose/types" "github.com/docker/docker/api/types/mount" - "github.com/pkg/errors" ) type volumes map[string]composetypes.VolumeConfig @@ -56,7 +57,7 @@ func handleVolumeToMount( stackVolume, exists := stackVolumes[volume.Source] if !exists { - return mount.Mount{}, errors.Errorf("undefined volume %q", volume.Source) + return mount.Mount{}, fmt.Errorf("undefined volume %q", volume.Source) } result.Source = namespace.Scope(volume.Source) @@ -180,7 +181,7 @@ func handleClusterToMount( // external volumes with a given group exist. stackVolume, exists := stackVolumes[volume.Source] if !exists { - return mount.Mount{}, errors.Errorf("undefined volume %q", volume.Source) + return mount.Mount{}, fmt.Errorf("undefined volume %q", volume.Source) } // if the volume is not specified with a group source, we may namespace diff --git a/cli/compose/interpolation/interpolation.go b/cli/compose/interpolation/interpolation.go index 11345a6a36..f399187258 100644 --- a/cli/compose/interpolation/interpolation.go +++ b/cli/compose/interpolation/interpolation.go @@ -9,7 +9,6 @@ import ( "strings" "github.com/docker/cli/cli/compose/template" - "github.com/pkg/errors" ) // Options supported by Interpolate @@ -105,11 +104,11 @@ func newPathError(path Path, err error) error { case nil: return nil case *template.InvalidTemplateError: - return errors.Errorf( + return fmt.Errorf( "invalid interpolation format for %s: %#v; you may need to escape any $ with another $", path, err.Template) default: - return errors.Wrapf(err, "error while interpolating %s", path) + return fmt.Errorf("error while interpolating %s: %w", path, err) } } diff --git a/cli/compose/loader/interpolate.go b/cli/compose/loader/interpolate.go index 68d3b8c329..1dde9f8dbe 100644 --- a/cli/compose/loader/interpolate.go +++ b/cli/compose/loader/interpolate.go @@ -4,11 +4,11 @@ package loader import ( + "fmt" "strconv" "strings" interp "github.com/docker/cli/cli/compose/interpolation" - "github.com/pkg/errors" ) var interpolateTypeCastMapping = map[interp.Path]interp.Cast{ @@ -67,7 +67,7 @@ func toBoolean(value string) (any, error) { case "n", "no", "false", "off": return false, nil default: - return nil, errors.Errorf("invalid boolean: %s", value) + return nil, fmt.Errorf("invalid boolean: %s", value) } } diff --git a/cli/compose/loader/loader.go b/cli/compose/loader/loader.go index ecf86af9b3..a2ff167bfb 100644 --- a/cli/compose/loader/loader.go +++ b/cli/compose/loader/loader.go @@ -4,6 +4,7 @@ package loader import ( + "errors" "fmt" "path" "path/filepath" @@ -23,7 +24,7 @@ import ( units "github.com/docker/go-units" "github.com/go-viper/mapstructure/v2" "github.com/google/shlex" - "github.com/pkg/errors" + "github.com/sirupsen/logrus" yaml "gopkg.in/yaml.v2" ) @@ -55,7 +56,7 @@ func ParseYAML(source []byte) (map[string]any, error) { } cfgMap, ok := cfg.(map[any]any) if !ok { - return nil, errors.Errorf("top-level object must be a mapping") + return nil, fmt.Errorf("top-level object must be a mapping") } converted, err := convertToStringKeysRecursive(cfgMap, "") if err != nil { @@ -67,7 +68,7 @@ func ParseYAML(source []byte) (map[string]any, error) { // Load reads a ConfigDetails and returns a fully loaded configuration func Load(configDetails types.ConfigDetails, opt ...func(*Options)) (*types.Config, error) { if len(configDetails.ConfigFiles) < 1 { - return nil, errors.Errorf("No files specified") + return nil, fmt.Errorf("No files specified") } options := &Options{ @@ -92,7 +93,7 @@ func Load(configDetails types.ConfigDetails, opt ...func(*Options)) (*types.Conf configDetails.Version = version } if configDetails.Version != version { - return nil, errors.Errorf("version mismatched between two composefiles : %v and %v", configDetails.Version, version) + return nil, fmt.Errorf("version mismatched between two composefiles : %v and %v", configDetails.Version, version) } if err := validateForbidden(configDict); err != nil { @@ -392,7 +393,7 @@ func formatInvalidKeyError(keyPrefix string, key any) error { } else { location = "in " + keyPrefix } - return errors.Errorf("non-string key %s: %#v", location, key) + return fmt.Errorf("non-string key %s: %#v", location, key) } // LoadServices produces a ServiceConfig map from a compose file Dict @@ -537,7 +538,7 @@ func transformUlimits(data any) (any, error) { ulimit.Hard = value["hard"].(int) return ulimit, nil default: - return data, errors.Errorf("invalid type %T for ulimits", value) + return data, fmt.Errorf("invalid type %T for ulimits", value) } } @@ -556,7 +557,7 @@ func LoadNetworks(source map[string]any, version string) (map[string]types.Netwo switch { case network.External.Name != "": if network.Name != "" { - return nil, errors.Errorf("network %s: network.external.name and network.name conflict; only use network.name", name) + return nil, fmt.Errorf("network %s: network.external.name and network.name conflict; only use network.name", name) } if versions.GreaterThanOrEqualTo(version, "3.5") { logrus.Warnf("network %s: network.external.name is deprecated in favor of network.name", name) @@ -573,7 +574,7 @@ func LoadNetworks(source map[string]any, version string) (map[string]types.Netwo } func externalVolumeError(volume, key string) error { - return errors.Errorf( + return fmt.Errorf( "conflicting parameters \"external\" and %q specified for volume %q", key, volume) } @@ -599,7 +600,7 @@ func LoadVolumes(source map[string]any, version string) (map[string]types.Volume return nil, externalVolumeError(name, "labels") case volume.External.Name != "": if volume.Name != "" { - return nil, errors.Errorf("volume %s: volume.external.name and volume.name conflict; only use volume.name", name) + return nil, fmt.Errorf("volume %s: volume.external.name and volume.name conflict; only use volume.name", name) } if versions.GreaterThanOrEqualTo(version, "3.4") { logrus.Warnf("volume %s: volume.external.name is deprecated in favor of volume.name", name) @@ -660,7 +661,7 @@ func loadFileObjectConfig(name string, objType string, obj types.FileObjectConfi // handle deprecated external.name if obj.External.Name != "" { if obj.Name != "" { - return obj, errors.Errorf("%[1]s %[2]s: %[1]s.external.name and %[1]s.name conflict; only use %[1]s.name", objType, name) + return obj, fmt.Errorf("%[1]s %[2]s: %[1]s.external.name and %[1]s.name conflict; only use %[1]s.name", objType, name) } if versions.GreaterThanOrEqualTo(details.Version, "3.5") { logrus.Warnf("%[1]s %[2]s: %[1]s.external.name is deprecated in favor of %[1]s.name", objType, name) @@ -673,7 +674,7 @@ func loadFileObjectConfig(name string, objType string, obj types.FileObjectConfi // if not "external: true" case obj.Driver != "": if obj.File != "" { - return obj, errors.Errorf("%[1]s %[2]s: %[1]s.driver and %[1]s.file conflict; only use %[1]s.driver", objType, name) + return obj, fmt.Errorf("%[1]s %[2]s: %[1]s.driver and %[1]s.file conflict; only use %[1]s.driver", objType, name) } default: obj.File = absPath(details.WorkingDir, obj.File) @@ -696,7 +697,7 @@ var transformMapStringString TransformerFunc = func(data any) (any, error) { case map[string]string: return value, nil default: - return data, errors.Errorf("invalid type %T for map[string]string", value) + return data, fmt.Errorf("invalid type %T for map[string]string", value) } } @@ -707,7 +708,7 @@ var transformExternal TransformerFunc = func(data any) (any, error) { case map[string]any: return map[string]any{"external": true, "name": value["name"]}, nil default: - return data, errors.Errorf("invalid type %T for external", value) + return data, fmt.Errorf("invalid type %T for external", value) } } @@ -735,12 +736,12 @@ var transformServicePort TransformerFunc = func(data any) (any, error) { case map[string]any: ports = append(ports, value) default: - return data, errors.Errorf("invalid type %T for port", value) + return data, fmt.Errorf("invalid type %T for port", value) } } return ports, nil default: - return data, errors.Errorf("invalid type %T for port", entries) + return data, fmt.Errorf("invalid type %T for port", entries) } } @@ -751,7 +752,7 @@ var transformStringSourceMap TransformerFunc = func(data any) (any, error) { case map[string]any: return data, nil default: - return data, errors.Errorf("invalid type %T for secret", value) + return data, fmt.Errorf("invalid type %T for secret", value) } } @@ -762,7 +763,7 @@ var transformBuildConfig TransformerFunc = func(data any) (any, error) { case map[string]any: return data, nil default: - return data, errors.Errorf("invalid type %T for service build", value) + return data, fmt.Errorf("invalid type %T for service build", value) } } @@ -773,7 +774,7 @@ var transformServiceVolumeConfig TransformerFunc = func(data any) (any, error) { case map[string]any: return data, nil default: - return data, errors.Errorf("invalid type %T for service volume", value) + return data, fmt.Errorf("invalid type %T for service volume", value) } } @@ -804,7 +805,7 @@ var transformStringList TransformerFunc = func(data any) (any, error) { case []any: return value, nil default: - return data, errors.Errorf("invalid type %T for string list", value) + return data, fmt.Errorf("invalid type %T for string list", value) } } @@ -851,7 +852,7 @@ func transformListOrMapping(listOrMapping any, sep string, allowNil bool, allowS } return result } - panic(errors.Errorf("expected a map or a list, got %T: %#v", listOrMapping, listOrMapping)) + panic(fmt.Errorf("expected a map or a list, got %T: %#v", listOrMapping, listOrMapping)) } func transformMappingOrListFunc(sep string, allowNil bool) TransformerFunc { @@ -879,7 +880,7 @@ func transformMappingOrList(mappingOrList any, sep string, allowNil bool) any { } return result } - panic(errors.Errorf("expected a map or a list, got %T: %#v", mappingOrList, mappingOrList)) + panic(fmt.Errorf("expected a map or a list, got %T: %#v", mappingOrList, mappingOrList)) } var transformShellCommand TransformerFunc = func(value any) (any, error) { @@ -896,7 +897,7 @@ var transformHealthCheckTest TransformerFunc = func(data any) (any, error) { case []any: return value, nil default: - return value, errors.Errorf("invalid type %T for healthcheck.test", value) + return value, fmt.Errorf("invalid type %T for healthcheck.test", value) } } @@ -907,7 +908,7 @@ var transformSize TransformerFunc = func(value any) (any, error) { case string: return units.RAMInBytes(value) } - panic(errors.Errorf("invalid type for size %T", value)) + panic(fmt.Errorf("invalid type for size %T", value)) } var transformStringToDuration TransformerFunc = func(value any) (any, error) { @@ -919,7 +920,7 @@ var transformStringToDuration TransformerFunc = func(value any) (any, error) { } return types.Duration(d), nil default: - return value, errors.Errorf("invalid type %T for duration", value) + return value, fmt.Errorf("invalid type %T for duration", value) } } diff --git a/cli/compose/loader/merge.go b/cli/compose/loader/merge.go index 94c4eebcea..b946349ac6 100644 --- a/cli/compose/loader/merge.go +++ b/cli/compose/loader/merge.go @@ -4,12 +4,12 @@ package loader import ( + "fmt" "reflect" "sort" "dario.cat/mergo" "github.com/docker/cli/cli/compose/types" - "github.com/pkg/errors" ) type specials struct { @@ -29,23 +29,23 @@ func merge(configs []*types.Config) (*types.Config, error) { var err error base.Services, err = mergeServices(base.Services, override.Services) if err != nil { - return base, errors.Wrapf(err, "cannot merge services from %s", override.Filename) + return base, fmt.Errorf("cannot merge services from %s: %w", override.Filename, err) } base.Volumes, err = mergeVolumes(base.Volumes, override.Volumes) if err != nil { - return base, errors.Wrapf(err, "cannot merge volumes from %s", override.Filename) + return base, fmt.Errorf("cannot merge volumes from %s: %w", override.Filename, err) } base.Networks, err = mergeNetworks(base.Networks, override.Networks) if err != nil { - return base, errors.Wrapf(err, "cannot merge networks from %s", override.Filename) + return base, fmt.Errorf("cannot merge networks from %s: %w", override.Filename, err) } base.Secrets, err = mergeSecrets(base.Secrets, override.Secrets) if err != nil { - return base, errors.Wrapf(err, "cannot merge secrets from %s", override.Filename) + return base, fmt.Errorf("cannot merge secrets from %s: %w", override.Filename, err) } base.Configs, err = mergeConfigs(base.Configs, override.Configs) if err != nil { - return base, errors.Wrapf(err, "cannot merge configs from %s", override.Filename) + return base, fmt.Errorf("cannot merge configs from %s: %w", override.Filename, err) } } return base, nil @@ -71,7 +71,7 @@ func mergeServices(base, override []types.ServiceConfig) ([]types.ServiceConfig, overrideService := overrideService if baseService, ok := baseServices[name]; ok { if err := mergo.Merge(&baseService, &overrideService, mergo.WithAppendSlice, mergo.WithOverride, mergo.WithTransformers(specials)); err != nil { - return base, errors.Wrapf(err, "cannot merge service %s", name) + return base, fmt.Errorf("cannot merge service %s: %w", name, err) } baseServices[name] = baseService continue @@ -89,7 +89,7 @@ func mergeServices(base, override []types.ServiceConfig) ([]types.ServiceConfig, func toServiceSecretConfigsMap(s any) (map[any]any, error) { secrets, ok := s.([]types.ServiceSecretConfig) if !ok { - return nil, errors.Errorf("not a serviceSecretConfig: %v", s) + return nil, fmt.Errorf("not a serviceSecretConfig: %v", s) } m := map[any]any{} for _, secret := range secrets { @@ -101,7 +101,7 @@ func toServiceSecretConfigsMap(s any) (map[any]any, error) { func toServiceConfigObjConfigsMap(s any) (map[any]any, error) { secrets, ok := s.([]types.ServiceConfigObjConfig) if !ok { - return nil, errors.Errorf("not a serviceSecretConfig: %v", s) + return nil, fmt.Errorf("not a serviceSecretConfig: %v", s) } m := map[any]any{} for _, secret := range secrets { @@ -113,7 +113,7 @@ func toServiceConfigObjConfigsMap(s any) (map[any]any, error) { func toServicePortConfigsMap(s any) (map[any]any, error) { ports, ok := s.([]types.ServicePortConfig) if !ok { - return nil, errors.Errorf("not a servicePortConfig slice: %v", s) + return nil, fmt.Errorf("not a servicePortConfig slice: %v", s) } m := map[any]any{} for _, p := range ports { @@ -125,7 +125,7 @@ func toServicePortConfigsMap(s any) (map[any]any, error) { func toServiceVolumeConfigsMap(s any) (map[any]any, error) { volumes, ok := s.([]types.ServiceVolumeConfig) if !ok { - return nil, errors.Errorf("not a serviceVolumeConfig slice: %v", s) + return nil, fmt.Errorf("not a serviceVolumeConfig slice: %v", s) } m := map[any]any{} for _, v := range volumes { @@ -212,7 +212,7 @@ func mergeSlice(tomap tomapFn, writeValue writeValueFromMapFn) func(dst, src ref func sliceToMap(tomap tomapFn, v reflect.Value) (map[any]any, error) { // check if valid if !v.IsValid() { - return nil, errors.Errorf("invalid value : %+v", v) + return nil, fmt.Errorf("invalid value : %+v", v) } return tomap(v.Interface()) } diff --git a/cli/compose/loader/volume.go b/cli/compose/loader/volume.go index f043f4aa57..7275eac60a 100644 --- a/cli/compose/loader/volume.go +++ b/cli/compose/loader/volume.go @@ -1,13 +1,14 @@ package loader import ( + "errors" + "fmt" "strings" "unicode" "unicode/utf8" "github.com/docker/cli/cli/compose/types" "github.com/docker/docker/api/types/mount" - "github.com/pkg/errors" ) const endOfSpec = rune(0) @@ -33,7 +34,7 @@ func ParseVolume(spec string) (types.ServiceVolumeConfig, error) { case char == ':' || char == endOfSpec: if err := populateFieldFromBuffer(char, buffer, &volume); err != nil { populateType(&volume) - return volume, errors.Wrapf(err, "invalid spec: %s", spec) + return volume, fmt.Errorf("invalid spec: %s: %w", spec, err) } buffer = []rune{} default: diff --git a/cli/compose/schema/schema.go b/cli/compose/schema/schema.go index b4861556a3..8ccfff2486 100644 --- a/cli/compose/schema/schema.go +++ b/cli/compose/schema/schema.go @@ -9,7 +9,6 @@ import ( "strings" "time" - "github.com/pkg/errors" "github.com/xeipuuv/gojsonschema" ) @@ -70,7 +69,7 @@ func Validate(config map[string]any, version string) error { version = normalizeVersion(version) schemaData, err := schemas.ReadFile("data/config_schema_v" + version + ".json") if err != nil { - return errors.Errorf("unsupported Compose file version: %s", version) + return fmt.Errorf("unsupported Compose file version: %s", version) } schemaLoader := gojsonschema.NewStringLoader(string(schemaData)) diff --git a/cli/config/config.go b/cli/config/config.go index 5a51843260..948e0a84df 100644 --- a/cli/config/config.go +++ b/cli/config/config.go @@ -13,7 +13,6 @@ import ( "github.com/docker/cli/cli/config/configfile" "github.com/docker/cli/cli/config/credentials" "github.com/docker/cli/cli/config/types" - "github.com/pkg/errors" ) const ( @@ -96,7 +95,7 @@ func SetDir(dir string) { func Path(p ...string) (string, error) { path := filepath.Join(append([]string{Dir()}, p...)...) if !strings.HasPrefix(path, Dir()+string(filepath.Separator)) { - return "", errors.Errorf("path %q is outside of root config directory %q", path, Dir()) + return "", fmt.Errorf("path %q is outside of root config directory %q", path, Dir()) } return path, nil } @@ -138,12 +137,12 @@ func load(configDir string) (*configfile.ConfigFile, error) { return configFile, nil } // Any other error happening when failing to read the file must be returned. - return configFile, errors.Wrap(err, "loading config file") + return configFile, fmt.Errorf("loading config file: %w", err) } defer file.Close() err = configFile.LoadFromReader(file) if err != nil { - err = errors.Wrapf(err, "loading config file: %s: ", filename) + err = fmt.Errorf("loading config file: %s: : %w", filename, err) } return configFile, err } diff --git a/cli/config/configfile/file.go b/cli/config/configfile/file.go index ae9dcb3370..ab498e7881 100644 --- a/cli/config/configfile/file.go +++ b/cli/config/configfile/file.go @@ -3,6 +3,8 @@ package configfile import ( "encoding/base64" "encoding/json" + "errors" + "fmt" "io" "os" "path/filepath" @@ -10,7 +12,7 @@ import ( "github.com/docker/cli/cli/config/credentials" "github.com/docker/cli/cli/config/types" - "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) @@ -138,7 +140,7 @@ func (configFile *ConfigFile) SaveToWriter(writer io.Writer) error { // Save encodes and writes out all the authorization information func (configFile *ConfigFile) Save() (retErr error) { if configFile.Filename == "" { - return errors.Errorf("Can't save config with empty filename") + return fmt.Errorf("Can't save config with empty filename") } dir := filepath.Dir(configFile.Filename) @@ -164,7 +166,7 @@ func (configFile *ConfigFile) Save() (retErr error) { } if err := temp.Close(); err != nil { - return errors.Wrap(err, "error closing temp file") + return fmt.Errorf("error closing temp file: %w", err) } // Handle situation where the configfile is a symlink @@ -242,11 +244,11 @@ func decodeAuth(authStr string) (string, string, error) { return "", "", err } if n > decLen { - return "", "", errors.Errorf("Something went wrong decoding auth config") + return "", "", fmt.Errorf("Something went wrong decoding auth config") } userName, password, ok := strings.Cut(string(decoded), ":") if !ok || userName == "" { - return "", "", errors.Errorf("Invalid auth configuration file") + return "", "", fmt.Errorf("Invalid auth configuration file") } return userName, strings.Trim(password, "\x00"), nil } diff --git a/cli/config/credentials/native_store_test.go b/cli/config/credentials/native_store_test.go index 5abcca3587..9eee381033 100644 --- a/cli/config/credentials/native_store_test.go +++ b/cli/config/credentials/native_store_test.go @@ -10,7 +10,7 @@ import ( "github.com/docker/cli/cli/config/types" "github.com/docker/docker-credential-helpers/client" "github.com/docker/docker-credential-helpers/credentials" - "github.com/pkg/errors" + "gotest.tools/v3/assert" is "gotest.tools/v3/assert/cmp" ) @@ -22,7 +22,7 @@ const ( missingCredsAddress = "https://missing.docker.io/v1" ) -var errCommandExited = errors.Errorf("exited 1") +var errCommandExited = fmt.Errorf("exited 1") // mockCommand simulates interactions between the docker client and a remote // credentials helper. diff --git a/cli/connhelper/commandconn/commandconn.go b/cli/connhelper/commandconn/commandconn.go index cfc2b86a25..fc2db26c7d 100644 --- a/cli/connhelper/commandconn/commandconn.go +++ b/cli/connhelper/commandconn/commandconn.go @@ -28,7 +28,6 @@ import ( "syscall" "time" - "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -139,7 +138,7 @@ func (c *commandConn) handleEOF(err error) error { c.stderrMu.Lock() stderr := c.stderr.String() c.stderrMu.Unlock() - return errors.Errorf("command %v did not exit after %v: stderr=%q", c.cmd.Args, err, stderr) + return fmt.Errorf("command %v did not exit after %v: stderr=%q", c.cmd.Args, err, stderr) } } @@ -149,7 +148,7 @@ func (c *commandConn) handleEOF(err error) error { c.stderrMu.Lock() stderr := c.stderr.String() c.stderrMu.Unlock() - return errors.Errorf("command %v has exited with %v, make sure the URL is valid, and Docker 18.09 or later is installed on the remote host: stderr=%s", c.cmd.Args, werr, stderr) + return fmt.Errorf("command %v has exited with %v, make sure the URL is valid, and Docker 18.09 or later is installed on the remote host: stderr=%s", c.cmd.Args, werr, stderr) } func ignorableCloseError(err error) bool { diff --git a/cli/connhelper/connhelper.go b/cli/connhelper/connhelper.go index 152d3e2953..9e3347c84c 100644 --- a/cli/connhelper/connhelper.go +++ b/cli/connhelper/connhelper.go @@ -3,13 +3,13 @@ package connhelper import ( "context" + "fmt" "net" "net/url" "strings" "github.com/docker/cli/cli/connhelper/commandconn" "github.com/docker/cli/cli/connhelper/ssh" - "github.com/pkg/errors" ) // ConnectionHelper allows to connect to a remote host with custom stream provider binary. @@ -43,7 +43,7 @@ func getConnectionHelper(daemonURL string, sshFlags []string) (*ConnectionHelper if u.Scheme == "ssh" { sp, err := ssh.ParseURL(daemonURL) if err != nil { - return nil, errors.Wrap(err, "ssh host connection is not valid") + return nil, fmt.Errorf("ssh host connection is not valid: %w", err) } sshFlags = addSSHTimeout(sshFlags) sshFlags = disablePseudoTerminalAllocation(sshFlags) diff --git a/cli/connhelper/ssh/ssh.go b/cli/connhelper/ssh/ssh.go index fb4c911105..79ea62f2e6 100644 --- a/cli/connhelper/ssh/ssh.go +++ b/cli/connhelper/ssh/ssh.go @@ -2,9 +2,9 @@ package ssh import ( + "errors" + "fmt" "net/url" - - "github.com/pkg/errors" ) // ParseURL parses URL @@ -14,7 +14,7 @@ func ParseURL(daemonURL string) (*Spec, error) { return nil, err } if u.Scheme != "ssh" { - return nil, errors.Errorf("expected scheme ssh, got %q", u.Scheme) + return nil, fmt.Errorf("expected scheme ssh, got %q", u.Scheme) } var sp Spec @@ -27,15 +27,15 @@ func ParseURL(daemonURL string) (*Spec, error) { } sp.Host = u.Hostname() if sp.Host == "" { - return nil, errors.Errorf("no host specified") + return nil, fmt.Errorf("no host specified") } sp.Port = u.Port() sp.Path = u.Path if u.RawQuery != "" { - return nil, errors.Errorf("extra query after the host: %q", u.RawQuery) + return nil, fmt.Errorf("extra query after the host: %q", u.RawQuery) } if u.Fragment != "" { - return nil, errors.Errorf("extra fragment after the host: %q", u.Fragment) + return nil, fmt.Errorf("extra fragment after the host: %q", u.Fragment) } return &sp, err } diff --git a/cli/context/docker/load.go b/cli/context/docker/load.go index 700b73c940..781b271dd6 100644 --- a/cli/context/docker/load.go +++ b/cli/context/docker/load.go @@ -4,6 +4,8 @@ import ( "crypto/tls" "crypto/x509" "encoding/pem" + "errors" + "fmt" "net" "net/http" "time" @@ -13,7 +15,6 @@ import ( "github.com/docker/cli/cli/context/store" "github.com/docker/docker/client" "github.com/docker/go-connections/tlsconfig" - "github.com/pkg/errors" ) // EndpointMeta is a typed wrapper around a context-store generic endpoint describing @@ -67,7 +68,7 @@ func (ep *Endpoint) tlsConfig() (*tls.Config, error) { x509cert, err := tls.X509KeyPair(ep.TLSData.Cert, keyBytes) if err != nil { - return nil, errors.Wrap(err, "failed to retrieve context tls info") + return nil, fmt.Errorf("failed to retrieve context tls info: %w", err) } tlsOpts = append(tlsOpts, func(cfg *tls.Config) { cfg.Certificates = []tls.Certificate{x509cert} @@ -143,7 +144,7 @@ func EndpointFromContext(metadata store.Metadata) (EndpointMeta, error) { } typed, ok := ep.(EndpointMeta) if !ok { - return EndpointMeta{}, errors.Errorf("endpoint %q is not of type EndpointMeta", DockerEndpoint) + return EndpointMeta{}, fmt.Errorf("endpoint %q is not of type EndpointMeta", DockerEndpoint) } return typed, nil } diff --git a/cli/context/store/metadatastore.go b/cli/context/store/metadatastore.go index 0c6986fa75..25ef53e279 100644 --- a/cli/context/store/metadatastore.go +++ b/cli/context/store/metadatastore.go @@ -5,6 +5,7 @@ package store import ( "encoding/json" + "errors" "fmt" "os" "path/filepath" @@ -14,7 +15,6 @@ import ( "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/ioutils" "github.com/fvbommel/sortorder" - "github.com/pkg/errors" ) const ( @@ -64,7 +64,7 @@ func parseTypedOrMap(payload []byte, getter TypeGetter) (any, error) { func (s *metadataStore) get(name string) (Metadata, error) { m, err := s.getByID(contextdirOf(name)) if err != nil { - return m, errors.Wrapf(err, "context %q", name) + return m, fmt.Errorf("context %q: %w", name, err) } return m, nil } @@ -74,7 +74,7 @@ func (s *metadataStore) getByID(id contextdir) (Metadata, error) { bytes, err := os.ReadFile(fileName) if err != nil { if errors.Is(err, os.ErrNotExist) { - return Metadata{}, errdefs.NotFound(errors.Wrap(err, "context not found")) + return Metadata{}, errdefs.NotFound(fmt.Errorf("context not found: %w", err)) } return Metadata{}, err } @@ -99,7 +99,7 @@ func (s *metadataStore) getByID(id contextdir) (Metadata, error) { func (s *metadataStore) remove(name string) error { if err := os.RemoveAll(s.contextDir(contextdirOf(name))); err != nil { - return errors.Wrapf(err, "failed to remove metadata") + return fmt.Errorf("failed to remove metadata: %w", err) } return nil } @@ -119,7 +119,7 @@ func (s *metadataStore) list() ([]Metadata, error) { if errors.Is(err, os.ErrNotExist) { continue } - return nil, errors.Wrap(err, "failed to read metadata") + return nil, fmt.Errorf("failed to read metadata: %w", err) } res = append(res, c) } diff --git a/cli/context/store/store.go b/cli/context/store/store.go index 894c732be6..92f36444b3 100644 --- a/cli/context/store/store.go +++ b/cli/context/store/store.go @@ -10,6 +10,7 @@ import ( "bytes" _ "crypto/sha256" // ensure ids can be computed "encoding/json" + "errors" "fmt" "io" "net/http" @@ -20,7 +21,6 @@ import ( "github.com/docker/docker/errdefs" "github.com/opencontainers/go-digest" - "github.com/pkg/errors" ) const restrictedNamePattern = "^[a-zA-Z0-9][a-zA-Z0-9_.+-]+$" @@ -147,10 +147,10 @@ func (s *ContextStore) CreateOrUpdate(meta Metadata) error { // Remove deletes the context with the given name, if found. func (s *ContextStore) Remove(name string) error { if err := s.meta.remove(name); err != nil { - return errors.Wrapf(err, "failed to remove context %s", name) + return fmt.Errorf("failed to remove context %s: %w", name, err) } if err := s.tls.remove(name); err != nil { - return errors.Wrapf(err, "failed to remove context %s", name) + return fmt.Errorf("failed to remove context %s: %w", name, err) } return nil } @@ -227,7 +227,7 @@ func ValidateContextName(name string) error { return errors.New(`"default" is a reserved context name`) } if !restrictedNameRegEx.MatchString(name) { - return errors.Errorf("context name %q is invalid, names are validated against regexp %q", name, restrictedNamePattern) + return fmt.Errorf("context name %q is invalid, names are validated against regexp %q", name, restrictedNamePattern) } return nil } diff --git a/cli/context/store/tlsstore.go b/cli/context/store/tlsstore.go index ffbbde7c0d..344514abd3 100644 --- a/cli/context/store/tlsstore.go +++ b/cli/context/store/tlsstore.go @@ -1,12 +1,12 @@ package store import ( + "fmt" "os" "path/filepath" "github.com/docker/docker/errdefs" "github.com/docker/docker/pkg/ioutils" - "github.com/pkg/errors" ) const tlsDir = "tls" @@ -39,9 +39,9 @@ func (s *tlsStore) getData(name, endpointName, filename string) ([]byte, error) data, err := os.ReadFile(filepath.Join(s.endpointDir(name, endpointName), filename)) if err != nil { if os.IsNotExist(err) { - return nil, errdefs.NotFound(errors.Errorf("TLS data for %s/%s/%s does not exist", name, endpointName, filename)) + return nil, errdefs.NotFound(fmt.Errorf("TLS data for %s/%s/%s does not exist", name, endpointName, filename)) } - return nil, errors.Wrapf(err, "failed to read TLS data for endpoint %s", endpointName) + return nil, fmt.Errorf("failed to read TLS data for endpoint %s: %w", endpointName, err) } return data, nil } @@ -49,14 +49,14 @@ func (s *tlsStore) getData(name, endpointName, filename string) ([]byte, error) // remove deletes all TLS data for the given context. func (s *tlsStore) remove(name string) error { if err := os.RemoveAll(s.contextDir(name)); err != nil { - return errors.Wrapf(err, "failed to remove TLS data") + return fmt.Errorf("failed to remove TLS data: %w", err) } return nil } func (s *tlsStore) removeEndpoint(name, endpointName string) error { if err := os.RemoveAll(s.endpointDir(name, endpointName)); err != nil { - return errors.Wrapf(err, "failed to remove TLS data for endpoint %s", endpointName) + return fmt.Errorf("failed to remove TLS data for endpoint %s: %w", endpointName, err) } return nil } @@ -68,7 +68,7 @@ func (s *tlsStore) listContextData(name string) (map[string]EndpointFiles, error if os.IsNotExist(err) { return map[string]EndpointFiles{}, nil } - return nil, errors.Wrapf(err, "failed to list TLS files for context %s", name) + return nil, fmt.Errorf("failed to list TLS files for context %s: %w", name, err) } r := make(map[string]EndpointFiles) for _, epFS := range epFSs { @@ -78,7 +78,7 @@ func (s *tlsStore) listContextData(name string) (map[string]EndpointFiles, error continue } if err != nil { - return nil, errors.Wrapf(err, "failed to list TLS files for endpoint %s", epFS.Name()) + return nil, fmt.Errorf("failed to list TLS files for endpoint %s: %w", epFS.Name(), err) } var files EndpointFiles for _, fs := range fss { diff --git a/cli/context/tlsdata.go b/cli/context/tlsdata.go index c758612a1d..5ffbad6e27 100644 --- a/cli/context/tlsdata.go +++ b/cli/context/tlsdata.go @@ -1,10 +1,11 @@ package context import ( + "fmt" "os" "github.com/docker/cli/cli/context/store" - "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) @@ -45,14 +46,14 @@ func (data *TLSData) ToStoreTLSData() *store.EndpointTLSData { func LoadTLSData(s store.Reader, contextName, endpointName string) (*TLSData, error) { tlsFiles, err := s.ListTLSFiles(contextName) if err != nil { - return nil, errors.Wrapf(err, "failed to retrieve TLS files for context %q", contextName) + return nil, fmt.Errorf("failed to retrieve TLS files for context %q: %w", contextName, err) } if epTLSFiles, ok := tlsFiles[endpointName]; ok { var tlsData TLSData for _, f := range epTLSFiles { data, err := s.GetTLSData(contextName, endpointName, f) if err != nil { - return nil, errors.Wrapf(err, "failed to retrieve TLS data (%s) for context %q", f, contextName) + return nil, fmt.Errorf("failed to retrieve TLS data (%s) for context %q: %w", f, contextName, err) } switch f { case caKey: diff --git a/cli/manifest/store/store.go b/cli/manifest/store/store.go index c4f8219cec..951d9b2552 100644 --- a/cli/manifest/store/store.go +++ b/cli/manifest/store/store.go @@ -2,6 +2,7 @@ package store import ( "encoding/json" + "fmt" "os" "path/filepath" "strings" @@ -11,7 +12,6 @@ import ( "github.com/docker/distribution/manifest/manifestlist" "github.com/opencontainers/go-digest" ocispec "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/pkg/errors" ) // Store manages local storage of image distribution manifests @@ -72,7 +72,7 @@ func (s *fsStore) getFromFilename(ref reference.Reference, filename string) (typ return types.ImageManifest{}, err } if dgst := digest.FromBytes(raw); dgst != manifestInfo.Digest { - return types.ImageManifest{}, errors.Errorf("invalid manifest file %v: image manifest digest mismatch (%v != %v)", filename, manifestInfo.Digest, dgst) + return types.ImageManifest{}, fmt.Errorf("invalid manifest file %v: image manifest digest mismatch (%v != %v)", filename, manifestInfo.Digest, dgst) } manifestInfo.ImageManifest.Descriptor = ocispec.Descriptor{ Digest: manifestInfo.Digest, diff --git a/cli/manifest/types/types.go b/cli/manifest/types/types.go index e098928de9..b901c263fe 100644 --- a/cli/manifest/types/types.go +++ b/cli/manifest/types/types.go @@ -2,6 +2,7 @@ package types import ( "encoding/json" + "fmt" "github.com/distribution/reference" "github.com/docker/distribution" @@ -10,7 +11,6 @@ import ( "github.com/docker/distribution/manifest/schema2" "github.com/opencontainers/go-digest" ocispec "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/pkg/errors" ) // ImageManifest contains info to output for a manifest object. @@ -82,7 +82,7 @@ func (i ImageManifest) Payload() (string, []byte, error) { case i.OCIManifest != nil: return i.OCIManifest.Payload() default: - return "", nil, errors.Errorf("%s has no payload", i.Ref) + return "", nil, fmt.Errorf("%s has no payload", i.Ref) } } @@ -141,7 +141,7 @@ type SerializableNamed struct { func (s *SerializableNamed) UnmarshalJSON(b []byte) error { var raw string if err := json.Unmarshal(b, &raw); err != nil { - return errors.Wrapf(err, "invalid named reference bytes: %s", b) + return fmt.Errorf("invalid named reference bytes: %s: %w", b, err) } var err error s.Named, err = reference.ParseNamed(raw) diff --git a/cli/registry/client/client.go b/cli/registry/client/client.go index 9256c041fb..66e2e8075b 100644 --- a/cli/registry/client/client.go +++ b/cli/registry/client/client.go @@ -13,7 +13,7 @@ import ( distributionclient "github.com/docker/distribution/registry/client" registrytypes "github.com/docker/docker/api/types/registry" "github.com/opencontainers/go-digest" - "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) @@ -90,7 +90,7 @@ func (c *client) MountBlob(ctx context.Context, sourceRef reference.Canonical, t return nil case nil: default: - return errors.Wrapf(err, "failed to mount blob %s to %s", sourceRef, targetRef) + return fmt.Errorf("failed to mount blob %s to %s: %w", sourceRef, targetRef, err) } lu.Cancel(ctx) logrus.Debugf("mount of blob %s created", sourceRef) @@ -130,7 +130,7 @@ func (c *client) PutManifest(ctx context.Context, ref reference.Named, manifest func (c *client) getRepositoryForReference(ctx context.Context, ref reference.Named, repoEndpoint repositoryEndpoint) (distribution.Repository, error) { repoName, err := reference.WithName(repoEndpoint.Name()) if err != nil { - return nil, errors.Wrapf(err, "failed to parse repo name from %s", ref) + return nil, fmt.Errorf("failed to parse repo name from %s: %w", ref, err) } httpTransport, err := c.getHTTPTransportForRepoEndpoint(ctx, repoEndpoint) if err != nil { @@ -200,5 +200,5 @@ func getManifestOptionsFromReference(ref reference.Named) (digest.Digest, []dist if digested, isDigested := ref.(reference.Canonical); isDigested { return digested.Digest(), []distribution.ManifestServiceOption{}, nil } - return "", nil, errors.Errorf("%s no tag or digest", ref) + return "", nil, fmt.Errorf("%s no tag or digest", ref) } diff --git a/cli/registry/client/endpoint.go b/cli/registry/client/endpoint.go index e06bfea50b..2b44d25dbe 100644 --- a/cli/registry/client/endpoint.go +++ b/cli/registry/client/endpoint.go @@ -1,6 +1,7 @@ package client import ( + "fmt" "net" "net/http" "time" @@ -11,7 +12,6 @@ import ( "github.com/docker/distribution/registry/client/transport" registrytypes "github.com/docker/docker/api/types/registry" "github.com/docker/docker/registry" - "github.com/pkg/errors" ) type repositoryEndpoint struct { @@ -92,7 +92,7 @@ func getHTTPTransport(authConfig registrytypes.AuthConfig, endpoint registry.API authTransport := transport.NewTransport(base, modifiers...) challengeManager, err := registry.PingV2Registry(endpoint.URL, authTransport) if err != nil { - return nil, errors.Wrap(err, "error pinging v2 registry") + return nil, fmt.Errorf("error pinging v2 registry: %w", err) } if authConfig.RegistryToken != "" { passThruTokenHandler := &existingTokenHandler{token: authConfig.RegistryToken} diff --git a/cli/registry/client/fetcher.go b/cli/registry/client/fetcher.go index 3e4b36d309..7e2303cca1 100644 --- a/cli/registry/client/fetcher.go +++ b/cli/registry/client/fetcher.go @@ -3,6 +3,8 @@ package client import ( "context" "encoding/json" + "errors" + "fmt" "github.com/distribution/reference" "github.com/docker/cli/cli/manifest/types" @@ -16,7 +18,7 @@ import ( "github.com/docker/docker/registry" "github.com/opencontainers/go-digest" ocispec "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) @@ -35,9 +37,9 @@ func fetchManifest(ctx context.Context, repo distribution.Repository, ref refere case *ocischema.DeserializedManifest: return pullManifestOCISchema(ctx, ref, repo, *v) case *manifestlist.DeserializedManifestList: - return types.ImageManifest{}, errors.Errorf("%s is a manifest list", ref) + return types.ImageManifest{}, fmt.Errorf("%s is a manifest list", ref) } - return types.ImageManifest{}, errors.Errorf("%s is not a manifest", ref) + return types.ImageManifest{}, fmt.Errorf("%s is not a manifest", ref) } func fetchList(ctx context.Context, repo distribution.Repository, ref reference.Named) ([]types.ImageManifest, error) { @@ -50,7 +52,7 @@ func fetchList(ctx context.Context, repo distribution.Repository, ref reference. case *manifestlist.DeserializedManifestList: return pullManifestList(ctx, ref, repo, *v) default: - return nil, errors.Errorf("unsupported manifest format: %v", v) + return nil, fmt.Errorf("unsupported manifest format: %v", v) } } @@ -62,7 +64,7 @@ func getManifest(ctx context.Context, repo distribution.Repository, ref referenc dgst, opts, err := getManifestOptionsFromReference(ref) if err != nil { - return nil, errors.Errorf("image manifest for %q does not exist", ref) + return nil, fmt.Errorf("image manifest for %q does not exist", ref) } return manSvc.Get(ctx, dgst, opts...) } @@ -123,7 +125,7 @@ func pullManifestSchemaV2ImageConfig(ctx context.Context, dgst digest.Digest, re return nil, err } if !verifier.Verified() { - return nil, errors.Errorf("image config verification failed for digest %s", dgst) + return nil, fmt.Errorf("image config verification failed for digest %s", dgst) } return configJSON, nil } @@ -143,7 +145,7 @@ func validateManifestDigest(ref reference.Named, mfst distribution.Manifest) (oc // If pull by digest, then verify the manifest digest. if digested, isDigested := ref.(reference.Canonical); isDigested && digested.Digest() != desc.Digest { - return ocispec.Descriptor{}, errors.Errorf("manifest verification failed for digest %s", digested.Digest()) + return ocispec.Descriptor{}, fmt.Errorf("manifest verification failed for digest %s", digested.Digest()) } return desc, nil @@ -179,7 +181,7 @@ func pullManifestList(ctx context.Context, ref reference.Named, repo distributio case *ocischema.DeserializedManifest: imageManifest, err = pullManifestOCISchema(ctx, manifestRef, repo, *v) default: - err = errors.Errorf("unsupported manifest type: %T", manifest) + err = fmt.Errorf("unsupported manifest type: %T", manifest) } if err != nil { return nil, err diff --git a/cli/required.go b/cli/required.go index 6455e8867e..85e444230e 100644 --- a/cli/required.go +++ b/cli/required.go @@ -1,7 +1,8 @@ package cli import ( - "github.com/pkg/errors" + "fmt" + "github.com/spf13/cobra" ) @@ -12,7 +13,7 @@ func NoArgs(cmd *cobra.Command, args []string) error { } if cmd.HasSubCommands() { - return errors.Errorf( + return fmt.Errorf( "%[1]s: unknown command: %[2]s %[3]s\n\nUsage: %[4]s\n\nRun '%[2]s --help' for more information", binName(cmd), cmd.CommandPath(), @@ -21,7 +22,7 @@ func NoArgs(cmd *cobra.Command, args []string) error { ) } - return errors.Errorf( + return fmt.Errorf( "%[1]s: '%[2]s' accepts no arguments\n\nUsage: %[3]s\n\nRun '%[2]s --help' for more information", binName(cmd), cmd.CommandPath(), @@ -35,7 +36,7 @@ func RequiresMinArgs(minArgs int) cobra.PositionalArgs { if len(args) >= minArgs { return nil } - return errors.Errorf( + return fmt.Errorf( "%[1]s: '%[2]s' requires at least %[3]d %[4]s\n\nUsage: %[5]s\n\nSee '%[2]s --help' for more information", binName(cmd), cmd.CommandPath(), @@ -52,7 +53,7 @@ func RequiresMaxArgs(maxArgs int) cobra.PositionalArgs { if len(args) <= maxArgs { return nil } - return errors.Errorf( + return fmt.Errorf( "%[1]s: '%[2]s' requires at most %[3]d %[4]s\n\nUsage: %[5]s\n\nSRun '%[2]s --help' for more information", binName(cmd), cmd.CommandPath(), @@ -69,7 +70,7 @@ func RequiresRangeArgs(minArgs int, maxArgs int) cobra.PositionalArgs { if len(args) >= minArgs && len(args) <= maxArgs { return nil } - return errors.Errorf( + return fmt.Errorf( "%[1]s: '%[2]s' requires at least %[3]d and at most %[4]d %[5]s\n\nUsage: %[6]s\n\nRun '%[2]s --help' for more information", binName(cmd), cmd.CommandPath(), @@ -87,7 +88,7 @@ func ExactArgs(number int) cobra.PositionalArgs { if len(args) == number { return nil } - return errors.Errorf( + return fmt.Errorf( "%[1]s: '%[2]s' requires %[3]d %[4]s\n\nUsage: %[5]s\n\nRun '%[2]s --help' for more information", binName(cmd), cmd.CommandPath(), diff --git a/cli/trust/trust.go b/cli/trust/trust.go index 745cede76f..e246facbd3 100644 --- a/cli/trust/trust.go +++ b/cli/trust/trust.go @@ -3,6 +3,7 @@ package trust import ( "context" "encoding/json" + "fmt" "io" "net" "net/http" @@ -21,7 +22,7 @@ import ( "github.com/docker/docker/registry" "github.com/docker/go-connections/tlsconfig" "github.com/opencontainers/go-digest" - "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/theupdateframework/notary" "github.com/theupdateframework/notary/client" @@ -66,7 +67,7 @@ func Server(index *registrytypes.IndexInfo) (string, error) { if s := os.Getenv("DOCKER_CONTENT_TRUST_SERVER"); s != "" { urlObj, err := url.Parse(s) if err != nil || urlObj.Scheme != "https" { - return "", errors.Errorf("valid https URL required for trust server, got %s", s) + return "", fmt.Errorf("valid https URL required for trust server, got %s", s) } return s, nil @@ -213,27 +214,27 @@ func NotaryError(repoName string, err error) error { switch err.(type) { case *json.SyntaxError: logrus.Debugf("Notary syntax error: %s", err) - return errors.Errorf("Error: no trust data available for remote repository %s. Try running notary server and setting DOCKER_CONTENT_TRUST_SERVER to its HTTPS address?", repoName) + return fmt.Errorf("Error: no trust data available for remote repository %s. Try running notary server and setting DOCKER_CONTENT_TRUST_SERVER to its HTTPS address?", repoName) case signed.ErrExpired: - return errors.Errorf("Error: remote repository %s out-of-date: %v", repoName, err) + return fmt.Errorf("Error: remote repository %s out-of-date: %v", repoName, err) case trustmanager.ErrKeyNotFound: - return errors.Errorf("Error: signing keys for remote repository %s not found: %v", repoName, err) + return fmt.Errorf("Error: signing keys for remote repository %s not found: %v", repoName, err) case storage.NetworkError: - return errors.Errorf("Error: error contacting notary server: %v", err) + return fmt.Errorf("Error: error contacting notary server: %v", err) case storage.ErrMetaNotFound: - return errors.Errorf("Error: trust data missing for remote repository %s or remote repository not found: %v", repoName, err) + return fmt.Errorf("Error: trust data missing for remote repository %s or remote repository not found: %v", repoName, err) case trustpinning.ErrRootRotationFail, trustpinning.ErrValidationFail, signed.ErrInvalidKeyType: - return errors.Errorf("Warning: potential malicious behavior - trust data mismatch for remote repository %s: %v", repoName, err) + return fmt.Errorf("Warning: potential malicious behavior - trust data mismatch for remote repository %s: %v", repoName, err) case signed.ErrNoKeys: - return errors.Errorf("Error: could not find signing keys for remote repository %s, or could not decrypt signing key: %v", repoName, err) + return fmt.Errorf("Error: could not find signing keys for remote repository %s, or could not decrypt signing key: %v", repoName, err) case signed.ErrLowVersion: - return errors.Errorf("Warning: potential malicious behavior - trust data version is lower than expected for remote repository %s: %v", repoName, err) + return fmt.Errorf("Warning: potential malicious behavior - trust data version is lower than expected for remote repository %s: %v", repoName, err) case signed.ErrRoleThreshold: - return errors.Errorf("Warning: potential malicious behavior - trust data has insufficient signatures for remote repository %s: %v", repoName, err) + return fmt.Errorf("Warning: potential malicious behavior - trust data has insufficient signatures for remote repository %s: %v", repoName, err) case client.ErrRepositoryNotExist: - return errors.Errorf("Error: remote trust data does not exist for %s: %v", repoName, err) + return fmt.Errorf("Error: remote trust data does not exist for %s: %v", repoName, err) case signed.ErrInsufficientSignatures: - return errors.Errorf("Error: could not produce valid signature for %s. If Yubikey was used, was touch input provided?: %v", repoName, err) + return fmt.Errorf("Error: could not produce valid signature for %s. If Yubikey was used, was touch input provided?: %v", repoName, err) } return err @@ -280,7 +281,7 @@ func GetSignableRoles(repo client.Repository, target *client.Target) ([]data.Rol } if len(signableRoles) == 0 { - return signableRoles, errors.Errorf("no valid signing keys for delegation roles") + return signableRoles, fmt.Errorf("no valid signing keys for delegation roles") } return signableRoles, nil diff --git a/cmd/docker/aliases.go b/cmd/docker/aliases.go index 0a288843d0..216842ff58 100644 --- a/cmd/docker/aliases.go +++ b/cmd/docker/aliases.go @@ -1,12 +1,13 @@ package main import ( + "fmt" "os" "strings" pluginmanager "github.com/docker/cli/cli-plugins/manager" "github.com/docker/cli/cli/command" - "github.com/pkg/errors" + "github.com/spf13/cobra" ) @@ -26,11 +27,11 @@ func processAliases(dockerCli command.Cli, cmd *cobra.Command, args, osArgs []st for k, v := range aliasMap { if _, ok := allowedAliases[k]; !ok { - return args, osArgs, envs, errors.Errorf("not allowed to alias %q (allowed: %#v)", k, allowedAliases) + return args, osArgs, envs, fmt.Errorf("not allowed to alias %q (allowed: %#v)", k, allowedAliases) } if c, _, err := cmd.Find(strings.Split(v, " ")); err == nil { if !pluginmanager.IsPluginCommand(c) { - return args, osArgs, envs, errors.Errorf("not allowed to alias with builtin %q as target", v) + return args, osArgs, envs, fmt.Errorf("not allowed to alias with builtin %q as target", v) } } aliases = append(aliases, [2][]string{{k}, {v}}) diff --git a/cmd/docker/builder.go b/cmd/docker/builder.go index ecb73264e0..0d4aaf286c 100644 --- a/cmd/docker/builder.go +++ b/cmd/docker/builder.go @@ -1,6 +1,7 @@ package main import ( + "errors" "fmt" "io" "os" @@ -10,7 +11,7 @@ import ( pluginmanager "github.com/docker/cli/cli-plugins/manager" "github.com/docker/cli/cli/command" "github.com/docker/docker/api/types" - "github.com/pkg/errors" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -50,7 +51,7 @@ func processBuilder(dockerCli command.Cli, cmd *cobra.Command, args, osargs []st if v := os.Getenv("DOCKER_BUILDKIT"); v != "" { enabled, err := strconv.ParseBool(v) if err != nil { - return args, osargs, nil, errors.Wrap(err, "DOCKER_BUILDKIT environment variable expects boolean value") + return args, osargs, nil, fmt.Errorf("DOCKER_BUILDKIT environment variable expects boolean value: %w", err) } if !enabled { buildKitDisabled = true diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index 8b15b76f8e..6e49245a70 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -2,6 +2,7 @@ package main import ( "context" + "errors" "fmt" "io" "os" @@ -21,7 +22,7 @@ import ( platformsignals "github.com/docker/cli/cmd/docker/internal/signals" "github.com/docker/docker/api/types/versions" "github.com/docker/docker/errdefs" - "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -149,7 +150,7 @@ func setupHelpCommand(dockerCli command.Cli, rootCmd, helpCmd *cobra.Command) { return helpcmd.Run() } if !pluginmanager.IsNotFound(err) { - return errors.Errorf("unknown help topic: %v", strings.Join(args, " ")) + return fmt.Errorf("unknown help topic: %v", strings.Join(args, " ")) } } if origRunE != nil { diff --git a/docs/generate/generate.go b/docs/generate/generate.go index a12c7d4ccf..2d548e13c1 100644 --- a/docs/generate/generate.go +++ b/docs/generate/generate.go @@ -6,6 +6,8 @@ package main import ( + "errors" + "fmt" "log" "os" @@ -13,7 +15,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/commands" - "github.com/pkg/errors" + "github.com/spf13/cobra" "github.com/spf13/pflag" ) @@ -65,7 +67,7 @@ func gen(opts *options) error { return err } default: - return errors.Errorf("unknown format %q", format) + return fmt.Errorf("unknown format %q", format) } } diff --git a/e2e/testutils/plugins.go b/e2e/testutils/plugins.go index e194eef9a5..89ade90787 100644 --- a/e2e/testutils/plugins.go +++ b/e2e/testutils/plugins.go @@ -13,7 +13,7 @@ import ( "testing" "github.com/docker/docker/api/types" - "github.com/pkg/errors" + "gotest.tools/v3/assert" "gotest.tools/v3/fs" "gotest.tools/v3/icmd" @@ -87,7 +87,7 @@ func buildPlugin(t *testing.T, ctx context.Context) (string, error) { cmd.Env = append(os.Environ(), "CGO_ENABLED=0") if out, err := cmd.CombinedOutput(); err != nil { - return "", errors.Wrapf(err, "error building basic plugin bin: %s", string(out)) + return "", fmt.Errorf("error building basic plugin bin: %s: %w", string(out), err) } return installPath, nil diff --git a/internal/test/environment/testenv.go b/internal/test/environment/testenv.go index 7fe6880244..b1cf0d0294 100644 --- a/internal/test/environment/testenv.go +++ b/internal/test/environment/testenv.go @@ -1,6 +1,7 @@ package environment import ( + "errors" "fmt" "os" "strings" @@ -8,7 +9,7 @@ import ( "time" "github.com/docker/docker/client" - "github.com/pkg/errors" + "gotest.tools/v3/icmd" "gotest.tools/v3/poll" "gotest.tools/v3/skip" diff --git a/internal/test/output/output.go b/internal/test/output/output.go index 42f958790f..43eafa29e0 100644 --- a/internal/test/output/output.go +++ b/internal/test/output/output.go @@ -1,10 +1,9 @@ package output import ( + "fmt" "strings" "testing" - - "github.com/pkg/errors" ) // Assert checks output lines at specified locations @@ -30,7 +29,7 @@ func Prefix(expected string) func(string) error { if strings.HasPrefix(actual, expected) { return nil } - return errors.Errorf("expected %q to start with %q", actual, expected) + return fmt.Errorf("expected %q to start with %q", actual, expected) } } @@ -40,7 +39,7 @@ func Suffix(expected string) func(string) error { if strings.HasSuffix(actual, expected) { return nil } - return errors.Errorf("expected %q to end with %q", actual, expected) + return fmt.Errorf("expected %q to end with %q", actual, expected) } } @@ -50,7 +49,7 @@ func Contains(expected string) func(string) error { if strings.Contains(actual, expected) { return nil } - return errors.Errorf("expected %q to contain %q", actual, expected) + return fmt.Errorf("expected %q to contain %q", actual, expected) } } @@ -60,6 +59,6 @@ func Equals(expected string) func(string) error { if expected == actual { return nil } - return errors.Errorf("got %q, expected %q", actual, expected) + return fmt.Errorf("got %q, expected %q", actual, expected) } } diff --git a/opts/duration.go b/opts/duration.go index 5dc6eeaa73..d4fa562eef 100644 --- a/opts/duration.go +++ b/opts/duration.go @@ -1,9 +1,8 @@ package opts import ( + "fmt" "time" - - "github.com/pkg/errors" ) // PositiveDurationOpt is an option type for time.Duration that uses a pointer. @@ -20,7 +19,7 @@ func (d *PositiveDurationOpt) Set(s string) error { return err } if *d.DurationOpt.value < 0 { - return errors.Errorf("duration cannot be negative") + return fmt.Errorf("duration cannot be negative") } return nil } diff --git a/opts/env.go b/opts/env.go index 214d6f4400..675ddda962 100644 --- a/opts/env.go +++ b/opts/env.go @@ -1,10 +1,9 @@ package opts import ( + "errors" "os" "strings" - - "github.com/pkg/errors" ) // ValidateEnv validates an environment variable and returns it. diff --git a/opts/gpus.go b/opts/gpus.go index d671c263b6..7f5b867520 100644 --- a/opts/gpus.go +++ b/opts/gpus.go @@ -7,7 +7,6 @@ import ( "strings" "github.com/docker/docker/api/types/container" - "github.com/pkg/errors" ) // GpuOpts is a Value type for parsing mounts @@ -72,7 +71,7 @@ func (o *GpuOpts) Set(value string) error { r := csv.NewReader(strings.NewReader(val)) optFields, err := r.Read() if err != nil { - return errors.Wrap(err, "failed to read gpu options") + return fmt.Errorf("failed to read gpu options: %w", err) } req.Options = ConvertKVStringsToMap(optFields) default: diff --git a/opts/opts.go b/opts/opts.go index 157b30f34b..62fee761cf 100644 --- a/opts/opts.go +++ b/opts/opts.go @@ -1,6 +1,7 @@ package opts import ( + "errors" "fmt" "math/big" "net" @@ -10,7 +11,6 @@ import ( "github.com/docker/docker/api/types/filters" units "github.com/docker/go-units" - "github.com/pkg/errors" ) var ( diff --git a/service/logs/parse_logs.go b/service/logs/parse_logs.go index 9771f484f6..cc81f135ca 100644 --- a/service/logs/parse_logs.go +++ b/service/logs/parse_logs.go @@ -3,10 +3,9 @@ package logs import ( + "errors" "net/url" "strings" - - "github.com/pkg/errors" ) // ParseLogDetails parses a string of key value pairs in the form