From dfec976e844b31d77defb49ed8b270487036e3ed Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 10 Jun 2024 20:47:07 +0200 Subject: [PATCH] linting: fmt.Errorf can be replaced with errors.New (perfsprint) internal/test/cli.go:175:14: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("no notary client available unless defined") ^ cli/command/cli.go:318:29: fmt.Errorf can be replaced with errors.New (perfsprint) return docker.Endpoint{}, fmt.Errorf("no context store initialized") ^ cli/command/container/attach.go:161:11: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf(result.Error.Message) ^ cli/command/container/opts.go:577:16: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("--health-start-period cannot be negative") ^ cli/command/container/opts.go:580:16: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("--health-start-interval cannot be negative") ^ cli/command/container/stats.go:221:11: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("filtering is not supported when specifying a list of containers") ^ cli/command/container/attach_test.go:82:17: fmt.Errorf can be replaced with errors.New (perfsprint) expectedErr = fmt.Errorf("unexpected error") ^ cli/command/container/create_test.go:234:40: fmt.Errorf can be replaced with errors.New (perfsprint) return container.CreateResponse{}, fmt.Errorf("shouldn't try to pull image") ^ cli/command/container/list_test.go:150:17: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("error listing containers") ^ cli/command/container/rm_test.go:40:31: fmt.Errorf can be replaced with errors.New (perfsprint) return errdefs.NotFound(fmt.Errorf("Error: no such container: " + container)) ^ cli/command/container/run_test.go:138:40: fmt.Errorf can be replaced with errors.New (perfsprint) return container.CreateResponse{}, fmt.Errorf("shouldn't try to pull image") ^ cli/command/image/pull_test.go:115:49: fmt.Errorf can be replaced with errors.New (perfsprint) return io.NopCloser(strings.NewReader("")), fmt.Errorf("shouldn't try to pull image") ^ cli/command/network/connect.go:88:16: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("invalid key/value pair format in driver options") ^ cli/command/plugin/create_test.go:96:11: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("Error creating plugin") ^ cli/command/plugin/disable_test.go:32:12: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("Error disabling plugin") ^ cli/command/plugin/enable_test.go:32:12: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("failed to enable plugin") ^ cli/command/plugin/inspect_test.go:55:22: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, nil, fmt.Errorf("error inspecting plugin") ^ cli/command/plugin/install_test.go:43:17: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("Error installing plugin") ^ cli/command/plugin/install_test.go:51:17: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("(image) when fetching") ^ cli/command/plugin/install_test.go:95:17: fmt.Errorf can be replaced with errors.New (perfsprint) return nil, fmt.Errorf("should not try to install plugin") ^ cli/command/plugin/list_test.go:35:41: fmt.Errorf can be replaced with errors.New (perfsprint) return types.PluginsListResponse{}, fmt.Errorf("error listing plugins") ^ cli/command/plugin/remove_test.go:27:12: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("Error removing plugin") ^ cli/command/registry/login_test.go:36:46: fmt.Errorf can be replaced with errors.New (perfsprint) return registrytypes.AuthenticateOKBody{}, fmt.Errorf("Invalid Username or Password") ^ cli/command/registry/login_test.go:44:46: fmt.Errorf can be replaced with errors.New (perfsprint) return registrytypes.AuthenticateOKBody{}, fmt.Errorf(errUnknownUser) ^ cli/command/system/info.go:190:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("errors pretty printing info") ^ cli/command/system/prune.go:77:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf(`ERROR: The "until" filter is not supported with "--volumes"`) ^ cli/command/system/version_test.go:19:28: fmt.Errorf can be replaced with errors.New (perfsprint) return types.Version{}, fmt.Errorf("no server") ^ cli/command/trust/key_load.go:112:22: fmt.Errorf can be replaced with errors.New (perfsprint) return []byte{}, fmt.Errorf("could not decrypt key") ^ cli/command/trust/revoke.go:44:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("cannot use a digest reference for IMAGE:TAG") ^ cli/command/trust/revoke.go:105:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("no signed tags to remove") ^ cli/command/trust/signer_add.go:56:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("releases is a reserved keyword, please use a different signer name") ^ cli/command/trust/signer_add.go:60:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("path to a public key must be provided using the `--key` flag") ^ opts/config.go:71:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("source is required") ^ opts/mount.go:168:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("type is required") ^ opts/mount.go:172:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("target is required") ^ opts/network.go:90:11: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("network name/id is not specified") ^ opts/network.go:129:18: fmt.Errorf can be replaced with errors.New (perfsprint) return "", "", fmt.Errorf("invalid key value pair format in driver options") ^ opts/opts.go:404:13: fmt.Errorf can be replaced with errors.New (perfsprint) return 0, fmt.Errorf("value is too precise") ^ opts/opts.go:412:18: fmt.Errorf can be replaced with errors.New (perfsprint) return "", "", fmt.Errorf("empty string specified for links") ^ opts/parse.go:84:37: fmt.Errorf can be replaced with errors.New (perfsprint) return container.RestartPolicy{}, fmt.Errorf("invalid restart policy format: no policy provided before colon") ^ opts/parse.go:89:38: fmt.Errorf can be replaced with errors.New (perfsprint) return container.RestartPolicy{}, fmt.Errorf("invalid restart policy format: maximum retry count must be an integer") ^ opts/port.go:105:13: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("hostip is not supported") ^ opts/secret.go:70:10: fmt.Errorf can be replaced with errors.New (perfsprint) return fmt.Errorf("source is required") ^ opts/env_test.go:57:11: fmt.Errorf can be replaced with errors.New (perfsprint) err: fmt.Errorf("invalid environment variable: =a"), ^ opts/env_test.go:93:11: fmt.Errorf can be replaced with errors.New (perfsprint) err: fmt.Errorf("invalid environment variable: ="), ^ cli-plugins/manager/error_test.go:16:11: fmt.Errorf can be replaced with errors.New (perfsprint) inner := fmt.Errorf("testing") ^ Signed-off-by: Sebastiaan van Stijn --- cli-plugins/manager/error_test.go | 4 ++-- cli/command/cli.go | 2 +- cli/command/container/attach.go | 3 +-- cli/command/container/attach_test.go | 3 +-- cli/command/container/create_test.go | 3 +-- cli/command/container/list_test.go | 4 ++-- cli/command/container/opts.go | 4 ++-- cli/command/container/rm_test.go | 4 ++-- cli/command/container/run_test.go | 3 +-- cli/command/container/stats.go | 2 +- cli/command/image/pull_test.go | 3 ++- cli/command/network/connect.go | 4 ++-- cli/command/plugin/create_test.go | 12 +++++------- cli/command/plugin/disable_test.go | 6 +++--- cli/command/plugin/enable_test.go | 11 +++++------ cli/command/plugin/inspect_test.go | 4 ++-- cli/command/plugin/install_test.go | 10 +++++----- cli/command/plugin/list_test.go | 4 ++-- cli/command/plugin/remove_test.go | 6 +++--- cli/command/registry/login_test.go | 5 +++-- cli/command/system/info.go | 3 ++- cli/command/system/prune.go | 6 +++--- cli/command/system/version_test.go | 4 ++-- cli/command/trust/key_load.go | 2 +- cli/command/trust/revoke.go | 6 +++--- cli/command/trust/signer_add.go | 4 ++-- internal/test/cli.go | 4 ++-- opts/config.go | 3 ++- opts/env_test.go | 24 ++++++++++++------------ opts/mount.go | 4 ++-- opts/network.go | 7 ++++--- opts/opts.go | 6 +++--- opts/parse.go | 6 +++--- opts/port.go | 3 ++- opts/secret.go | 5 +++-- 35 files changed, 92 insertions(+), 92 deletions(-) diff --git a/cli-plugins/manager/error_test.go b/cli-plugins/manager/error_test.go index 55222d7042..c4cb19bd55 100644 --- a/cli-plugins/manager/error_test.go +++ b/cli-plugins/manager/error_test.go @@ -2,7 +2,7 @@ package manager import ( "encoding/json" - "fmt" + "errors" "testing" "gotest.tools/v3/assert" @@ -13,7 +13,7 @@ func TestPluginError(t *testing.T) { err := NewPluginError("new error") assert.Check(t, is.Error(err, "new error")) - inner := fmt.Errorf("testing") + inner := errors.New("testing") err = wrapAsPluginError(inner, "wrapping") assert.Check(t, is.Error(err, "wrapping: testing")) assert.Check(t, is.ErrorIs(err, inner)) diff --git a/cli/command/cli.go b/cli/command/cli.go index 28253f8c16..1d671135e6 100644 --- a/cli/command/cli.go +++ b/cli/command/cli.go @@ -315,7 +315,7 @@ func newAPIClientFromEndpoint(ep docker.Endpoint, configFile *configfile.ConfigF func resolveDockerEndpoint(s store.Reader, contextName string) (docker.Endpoint, error) { if s == nil { - return docker.Endpoint{}, fmt.Errorf("no context store initialized") + return docker.Endpoint{}, errors.New("no context store initialized") } ctxMeta, err := s.GetMetadata(contextName) if err != nil { diff --git a/cli/command/container/attach.go b/cli/command/container/attach.go index 7f1cb25824..a2d9838683 100644 --- a/cli/command/container/attach.go +++ b/cli/command/container/attach.go @@ -2,7 +2,6 @@ package container import ( "context" - "fmt" "io" "github.com/docker/cli/cli" @@ -158,7 +157,7 @@ func getExitStatus(errC <-chan error, resultC <-chan container.WaitResponse) err select { case result := <-resultC: if result.Error != nil { - return fmt.Errorf(result.Error.Message) + return errors.New(result.Error.Message) } if result.StatusCode != 0 { return cli.StatusError{StatusCode: int(result.StatusCode)} diff --git a/cli/command/container/attach_test.go b/cli/command/container/attach_test.go index b0aaea688c..7c16aec778 100644 --- a/cli/command/container/attach_test.go +++ b/cli/command/container/attach_test.go @@ -1,7 +1,6 @@ package container import ( - "fmt" "io" "testing" @@ -79,7 +78,7 @@ func TestNewAttachCommandErrors(t *testing.T) { func TestGetExitStatus(t *testing.T) { var ( - expectedErr = fmt.Errorf("unexpected error") + expectedErr = errors.New("unexpected error") errC = make(chan error, 1) resultC = make(chan container.WaitResponse, 1) ) diff --git a/cli/command/container/create_test.go b/cli/command/container/create_test.go index 36158dd3be..f77c699db3 100644 --- a/cli/command/container/create_test.go +++ b/cli/command/container/create_test.go @@ -3,7 +3,6 @@ package container import ( "context" "errors" - "fmt" "io" "os" "runtime" @@ -231,7 +230,7 @@ func TestNewCreateCommandWithContentTrustErrors(t *testing.T) { platform *specs.Platform, containerName string, ) (container.CreateResponse, error) { - return container.CreateResponse{}, fmt.Errorf("shouldn't try to pull image") + return container.CreateResponse{}, errors.New("shouldn't try to pull image") }, }, test.EnableContentTrust) fakeCLI.SetNotaryClient(tc.notaryFunc) diff --git a/cli/command/container/list_test.go b/cli/command/container/list_test.go index c426383005..6c80541870 100644 --- a/cli/command/container/list_test.go +++ b/cli/command/container/list_test.go @@ -1,7 +1,7 @@ package container import ( - "fmt" + "errors" "io" "testing" @@ -147,7 +147,7 @@ func TestContainerListErrors(t *testing.T) { }, { containerListFunc: func(_ container.ListOptions) ([]types.Container, error) { - return nil, fmt.Errorf("error listing containers") + return nil, errors.New("error listing containers") }, expectedError: "error listing containers", }, diff --git a/cli/command/container/opts.go b/cli/command/container/opts.go index 5ce22a6e4c..2a49259d29 100644 --- a/cli/command/container/opts.go +++ b/cli/command/container/opts.go @@ -574,10 +574,10 @@ func parse(flags *pflag.FlagSet, copts *containerOptions, serverOS string) (*con return nil, errors.Errorf("--health-retries cannot be negative") } if copts.healthStartPeriod < 0 { - return nil, fmt.Errorf("--health-start-period cannot be negative") + return nil, errors.New("--health-start-period cannot be negative") } if copts.healthStartInterval < 0 { - return nil, fmt.Errorf("--health-start-interval cannot be negative") + return nil, errors.New("--health-start-interval cannot be negative") } healthConfig = &container.HealthConfig{ diff --git a/cli/command/container/rm_test.go b/cli/command/container/rm_test.go index 3f36e890d5..704effbb59 100644 --- a/cli/command/container/rm_test.go +++ b/cli/command/container/rm_test.go @@ -2,7 +2,7 @@ package container import ( "context" - "fmt" + "errors" "io" "sort" "sync" @@ -37,7 +37,7 @@ func TestRemoveForce(t *testing.T) { mutex.Unlock() if container == "nosuchcontainer" { - return errdefs.NotFound(fmt.Errorf("Error: no such container: " + container)) + return errdefs.NotFound(errors.New("Error: no such container: " + container)) } return nil }, diff --git a/cli/command/container/run_test.go b/cli/command/container/run_test.go index 007fcb222c..d02956da1d 100644 --- a/cli/command/container/run_test.go +++ b/cli/command/container/run_test.go @@ -3,7 +3,6 @@ package container import ( "context" "errors" - "fmt" "io" "net" "os/signal" @@ -135,7 +134,7 @@ func TestRunCommandWithContentTrustErrors(t *testing.T) { platform *specs.Platform, containerName string, ) (container.CreateResponse, error) { - return container.CreateResponse{}, fmt.Errorf("shouldn't try to pull image") + return container.CreateResponse{}, errors.New("shouldn't try to pull image") }, }, test.EnableContentTrust) fakeCLI.SetNotaryClient(tc.notaryFunc) diff --git a/cli/command/container/stats.go b/cli/command/container/stats.go index 4ac158266a..dd5e35d5fa 100644 --- a/cli/command/container/stats.go +++ b/cli/command/container/stats.go @@ -218,7 +218,7 @@ func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions) // with a list of container names/IDs. if options.Filters != nil && options.Filters.Len() > 0 { - return fmt.Errorf("filtering is not supported when specifying a list of containers") + return errors.New("filtering is not supported when specifying a list of containers") } // Create the list of containers, and start collecting stats for all diff --git a/cli/command/image/pull_test.go b/cli/command/image/pull_test.go index 51e8ece6e6..3aa6e55244 100644 --- a/cli/command/image/pull_test.go +++ b/cli/command/image/pull_test.go @@ -1,6 +1,7 @@ package image import ( + "errors" "fmt" "io" "strings" @@ -112,7 +113,7 @@ func TestNewPullCommandWithContentTrustErrors(t *testing.T) { for _, tc := range testCases { cli := test.NewFakeCli(&fakeClient{ imagePullFunc: func(ref string, options image.PullOptions) (io.ReadCloser, error) { - return io.NopCloser(strings.NewReader("")), fmt.Errorf("shouldn't try to pull image") + return io.NopCloser(strings.NewReader("")), errors.New("shouldn't try to pull image") }, }, test.EnableContentTrust) cli.SetNotaryClient(tc.notaryFunc) diff --git a/cli/command/network/connect.go b/cli/command/network/connect.go index 8e20854944..22a685ef1d 100644 --- a/cli/command/network/connect.go +++ b/cli/command/network/connect.go @@ -2,7 +2,7 @@ package network import ( "context" - "fmt" + "errors" "strings" "github.com/docker/cli/cli" @@ -83,7 +83,7 @@ func convertDriverOpt(options []string) (map[string]string, error) { // TODO(thaJeztah): we should probably not accept whitespace here (both for key and value). k = strings.TrimSpace(k) if !ok || k == "" { - return nil, fmt.Errorf("invalid key/value pair format in driver options") + return nil, errors.New("invalid key/value pair format in driver options") } driverOpt[k] = strings.TrimSpace(v) } diff --git a/cli/command/plugin/create_test.go b/cli/command/plugin/create_test.go index 37ce5e22c4..e05eb60855 100644 --- a/cli/command/plugin/create_test.go +++ b/cli/command/plugin/create_test.go @@ -1,7 +1,7 @@ package plugin import ( - "fmt" + "errors" "io" "runtime" "testing" @@ -91,16 +91,14 @@ func TestCreateErrorFromDaemon(t *testing.T) { fs.WithFile("config.json", `{ "Name": "plugin-foo" }`)) defer tmpDir.Remove() - cli := test.NewFakeCli(&fakeClient{ + cmd := newCreateCommand(test.NewFakeCli(&fakeClient{ pluginCreateFunc: func(createContext io.Reader, createOptions types.PluginCreateOptions) error { - return fmt.Errorf("Error creating plugin") + return errors.New("error creating plugin") }, - }) - - cmd := newCreateCommand(cli) + })) cmd.SetArgs([]string{"plugin-foo", tmpDir.Path()}) cmd.SetOut(io.Discard) - assert.ErrorContains(t, cmd.Execute(), "Error creating plugin") + assert.ErrorContains(t, cmd.Execute(), "error creating plugin") } func TestCreatePlugin(t *testing.T) { diff --git a/cli/command/plugin/disable_test.go b/cli/command/plugin/disable_test.go index ca2e0d2cbb..cd78943c94 100644 --- a/cli/command/plugin/disable_test.go +++ b/cli/command/plugin/disable_test.go @@ -1,7 +1,7 @@ package plugin import ( - "fmt" + "errors" "io" "testing" @@ -27,9 +27,9 @@ func TestPluginDisableErrors(t *testing.T) { }, { args: []string{"plugin-foo"}, - expectedError: "Error disabling plugin", + expectedError: "error disabling plugin", pluginDisableFunc: func(name string, disableOptions types.PluginDisableOptions) error { - return fmt.Errorf("Error disabling plugin") + return errors.New("error disabling plugin") }, }, } diff --git a/cli/command/plugin/enable_test.go b/cli/command/plugin/enable_test.go index 1d8840e77c..0f22054756 100644 --- a/cli/command/plugin/enable_test.go +++ b/cli/command/plugin/enable_test.go @@ -1,7 +1,7 @@ package plugin import ( - "fmt" + "errors" "io" "testing" @@ -29,7 +29,7 @@ func TestPluginEnableErrors(t *testing.T) { { args: []string{"plugin-foo"}, pluginEnableFunc: func(name string, options types.PluginEnableOptions) error { - return fmt.Errorf("failed to enable plugin") + return errors.New("failed to enable plugin") }, expectedError: "failed to enable plugin", }, @@ -43,10 +43,9 @@ func TestPluginEnableErrors(t *testing.T) { } for _, tc := range testCases { - cmd := newEnableCommand( - test.NewFakeCli(&fakeClient{ - pluginEnableFunc: tc.pluginEnableFunc, - })) + cmd := newEnableCommand(test.NewFakeCli(&fakeClient{ + pluginEnableFunc: tc.pluginEnableFunc, + })) cmd.SetArgs(tc.args) for key, value := range tc.flags { cmd.Flags().Set(key, value) diff --git a/cli/command/plugin/inspect_test.go b/cli/command/plugin/inspect_test.go index 4d3127660a..f5c2ad5857 100644 --- a/cli/command/plugin/inspect_test.go +++ b/cli/command/plugin/inspect_test.go @@ -1,13 +1,13 @@ package plugin import ( + "errors" "fmt" "io" "testing" "github.com/docker/cli/internal/test" "github.com/docker/docker/api/types" - "gotest.tools/v3/assert" "gotest.tools/v3/golden" ) @@ -52,7 +52,7 @@ func TestInspectErrors(t *testing.T) { args: []string{"foo"}, expectedError: "error inspecting plugin", inspectFunc: func(name string) (*types.Plugin, []byte, error) { - return nil, nil, fmt.Errorf("error inspecting plugin") + return nil, nil, errors.New("error inspecting plugin") }, }, { diff --git a/cli/command/plugin/install_test.go b/cli/command/plugin/install_test.go index e49b582f83..03cad5f110 100644 --- a/cli/command/plugin/install_test.go +++ b/cli/command/plugin/install_test.go @@ -1,7 +1,7 @@ package plugin import ( - "fmt" + "errors" "io" "strings" "testing" @@ -38,9 +38,9 @@ func TestInstallErrors(t *testing.T) { { description: "installation error", args: []string{"foo"}, - expectedError: "Error installing plugin", + expectedError: "error installing plugin", installFunc: func(name string, options types.PluginInstallOptions) (io.ReadCloser, error) { - return nil, fmt.Errorf("Error installing plugin") + return nil, errors.New("error installing plugin") }, }, { @@ -48,7 +48,7 @@ func TestInstallErrors(t *testing.T) { args: []string{"foo"}, expectedError: "docker image pull", installFunc: func(name string, options types.PluginInstallOptions) (io.ReadCloser, error) { - return nil, fmt.Errorf("(image) when fetching") + return nil, errors.New("(image) when fetching") }, }, } @@ -92,7 +92,7 @@ func TestInstallContentTrustErrors(t *testing.T) { for _, tc := range testCases { cli := test.NewFakeCli(&fakeClient{ pluginInstallFunc: func(name string, options types.PluginInstallOptions) (io.ReadCloser, error) { - return nil, fmt.Errorf("should not try to install plugin") + return nil, errors.New("should not try to install plugin") }, }, test.EnableContentTrust) cli.SetNotaryClient(tc.notaryFunc) diff --git a/cli/command/plugin/list_test.go b/cli/command/plugin/list_test.go index ed30eb1c59..a5e4e71d31 100644 --- a/cli/command/plugin/list_test.go +++ b/cli/command/plugin/list_test.go @@ -1,7 +1,7 @@ package plugin import ( - "fmt" + "errors" "io" "testing" @@ -32,7 +32,7 @@ func TestListErrors(t *testing.T) { args: []string{}, expectedError: "error listing plugins", listFunc: func(filter filters.Args) (types.PluginsListResponse, error) { - return types.PluginsListResponse{}, fmt.Errorf("error listing plugins") + return types.PluginsListResponse{}, errors.New("error listing plugins") }, }, { diff --git a/cli/command/plugin/remove_test.go b/cli/command/plugin/remove_test.go index 36cfe0ba45..cf701cfa3b 100644 --- a/cli/command/plugin/remove_test.go +++ b/cli/command/plugin/remove_test.go @@ -1,7 +1,7 @@ package plugin import ( - "fmt" + "errors" "io" "testing" @@ -24,9 +24,9 @@ func TestRemoveErrors(t *testing.T) { { args: []string{"plugin-foo"}, pluginRemoveFunc: func(name string, options types.PluginRemoveOptions) error { - return fmt.Errorf("Error removing plugin") + return errors.New("error removing plugin") }, - expectedError: "Error removing plugin", + expectedError: "error removing plugin", }, } diff --git a/cli/command/registry/login_test.go b/cli/command/registry/login_test.go index acdb7a93f6..c8baa9535a 100644 --- a/cli/command/registry/login_test.go +++ b/cli/command/registry/login_test.go @@ -3,6 +3,7 @@ package registry import ( "bytes" "context" + "errors" "fmt" "testing" @@ -33,7 +34,7 @@ func (c fakeClient) Info(context.Context) (system.Info, error) { func (c fakeClient) RegistryLogin(_ context.Context, auth registrytypes.AuthConfig) (registrytypes.AuthenticateOKBody, error) { if auth.Password == expiredPassword { - return registrytypes.AuthenticateOKBody{}, fmt.Errorf("Invalid Username or Password") + return registrytypes.AuthenticateOKBody{}, errors.New("Invalid Username or Password") } if auth.Password == useToken { return registrytypes.AuthenticateOKBody{ @@ -41,7 +42,7 @@ func (c fakeClient) RegistryLogin(_ context.Context, auth registrytypes.AuthConf }, nil } if auth.Username == unknownUser { - return registrytypes.AuthenticateOKBody{}, fmt.Errorf(errUnknownUser) + return registrytypes.AuthenticateOKBody{}, errors.New(errUnknownUser) } return registrytypes.AuthenticateOKBody{}, nil } diff --git a/cli/command/system/info.go b/cli/command/system/info.go index 6d6416460a..29cacc47fe 100644 --- a/cli/command/system/info.go +++ b/cli/command/system/info.go @@ -5,6 +5,7 @@ package system import ( "context" + "errors" "fmt" "io" "regexp" @@ -187,7 +188,7 @@ func prettyPrintInfo(streams command.Streams, info dockerInfo) error { } if len(info.ServerErrors) > 0 || len(info.ClientErrors) > 0 { - return fmt.Errorf("errors pretty printing info") + return errors.New("errors pretty printing info") } return nil } diff --git a/cli/command/system/prune.go b/cli/command/system/prune.go index 4861f14ca3..815efdef76 100644 --- a/cli/command/system/prune.go +++ b/cli/command/system/prune.go @@ -74,7 +74,7 @@ Are you sure you want to continue?` func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) error { // TODO version this once "until" filter is supported for volumes if options.pruneVolumes && options.filter.Value().Contains("until") { - return fmt.Errorf(`ERROR: The "until" filter is not supported with "--volumes"`) + return errors.New(`ERROR: The "until" filter is not supported with "--volumes"`) } if !options.force { r, err := command.PromptForConfirmation(ctx, dockerCli.In(), dockerCli.Out(), confirmationMessage(dockerCli, options)) @@ -105,11 +105,11 @@ func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) } spaceReclaimed += spc if output != "" { - fmt.Fprintln(dockerCli.Out(), output) + _, _ = fmt.Fprintln(dockerCli.Out(), output) } } - fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed))) + _, _ = fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed))) return nil } diff --git a/cli/command/system/version_test.go b/cli/command/system/version_test.go index 5d7483c66c..c0cf642597 100644 --- a/cli/command/system/version_test.go +++ b/cli/command/system/version_test.go @@ -2,7 +2,7 @@ package system import ( "context" - "fmt" + "errors" "strings" "testing" @@ -16,7 +16,7 @@ import ( func TestVersionWithoutServer(t *testing.T) { cli := test.NewFakeCli(&fakeClient{ serverVersion: func(ctx context.Context) (types.Version, error) { - return types.Version{}, fmt.Errorf("no server") + return types.Version{}, errors.New("no server") }, }) cmd := NewVersionCommand(cli) diff --git a/cli/command/trust/key_load.go b/cli/command/trust/key_load.go index bbb19e733e..4a5bb26055 100644 --- a/cli/command/trust/key_load.go +++ b/cli/command/trust/key_load.go @@ -109,7 +109,7 @@ func decodePrivKeyIfNecessary(privPemBytes []byte, passRet notary.PassRetriever) if _, ok := pemBlock.Headers["path"]; !ok { privKey, _, err := trustmanager.GetPasswdDecryptBytes(passRet, privPemBytes, "", "encrypted") if err != nil { - return []byte{}, fmt.Errorf("could not decrypt key") + return []byte{}, errors.New("could not decrypt key") } privPemBytes = privKey.Private() } diff --git a/cli/command/trust/revoke.go b/cli/command/trust/revoke.go index 4a0d6e3af3..4e376b6454 100644 --- a/cli/command/trust/revoke.go +++ b/cli/command/trust/revoke.go @@ -41,7 +41,7 @@ func revokeTrust(ctx context.Context, dockerCLI command.Cli, remote string, opti } tag := imgRefAndAuth.Tag() if imgRefAndAuth.Tag() == "" && imgRefAndAuth.Digest() != "" { - return fmt.Errorf("cannot use a digest reference for IMAGE:TAG") + return errors.New("cannot use a digest reference for IMAGE:TAG") } if imgRefAndAuth.Tag() == "" && !options.forceYes { deleteRemote, err := command.PromptForConfirmation(ctx, dockerCLI.In(), dockerCLI.Out(), fmt.Sprintf("Please confirm you would like to delete all signature data for %s?", remote)) @@ -65,7 +65,7 @@ func revokeTrust(ctx context.Context, dockerCLI command.Cli, remote string, opti if err := revokeSignature(notaryRepo, tag); err != nil { return errors.Wrapf(err, "could not remove signature for %s", remote) } - fmt.Fprintf(dockerCLI.Out(), "Successfully deleted signature for %s\n", remote) + _, _ = fmt.Fprintf(dockerCLI.Out(), "Successfully deleted signature for %s\n", remote) return nil } @@ -102,7 +102,7 @@ func revokeAllSigs(notaryRepo client.Repository) error { } if len(releasedTargetWithRoleList) == 0 { - return fmt.Errorf("no signed tags to remove") + return errors.New("no signed tags to remove") } // we need all the roles that signed each released target so we can remove from all roles. diff --git a/cli/command/trust/signer_add.go b/cli/command/trust/signer_add.go index db6bcd7c34..b0f98e6f7b 100644 --- a/cli/command/trust/signer_add.go +++ b/cli/command/trust/signer_add.go @@ -53,11 +53,11 @@ func addSigner(ctx context.Context, dockerCLI command.Cli, options signerAddOpti return fmt.Errorf("signer name \"%s\" must start with lowercase alphanumeric characters and can include \"-\" or \"_\" after the first character", signerName) } if signerName == "releases" { - return fmt.Errorf("releases is a reserved keyword, please use a different signer name") + return errors.New("releases is a reserved keyword, please use a different signer name") } if options.keys.Len() == 0 { - return fmt.Errorf("path to a public key must be provided using the `--key` flag") + return errors.New("path to a public key must be provided using the `--key` flag") } signerPubKeys, err := ingestPublicKeys(options.keys.GetAll()) if err != nil { diff --git a/internal/test/cli.go b/internal/test/cli.go index 2315a7a1f2..588b80132a 100644 --- a/internal/test/cli.go +++ b/internal/test/cli.go @@ -2,7 +2,7 @@ package test import ( "bytes" - "fmt" + "errors" "io" "strings" @@ -172,7 +172,7 @@ func (c *FakeCli) NotaryClient(imgRefAndAuth trust.ImageRefAndAuth, actions []st if c.notaryClientFunc != nil { return c.notaryClientFunc(imgRefAndAuth, actions) } - return nil, fmt.Errorf("no notary client available unless defined") + return nil, errors.New("no notary client available unless defined") } // ManifestStore returns a fake store used for testing diff --git a/opts/config.go b/opts/config.go index 3be0fa93dd..1423ae3be5 100644 --- a/opts/config.go +++ b/opts/config.go @@ -2,6 +2,7 @@ package opts import ( "encoding/csv" + "errors" "fmt" "os" "strconv" @@ -68,7 +69,7 @@ func (o *ConfigOpt) Set(value string) error { } if options.ConfigName == "" { - return fmt.Errorf("source is required") + return errors.New("source is required") } if options.File.Name == "" { options.File.Name = options.ConfigName diff --git a/opts/env_test.go b/opts/env_test.go index 3561ceb314..a8a565be2a 100644 --- a/opts/env_test.go +++ b/opts/env_test.go @@ -11,9 +11,9 @@ import ( func TestValidateEnv(t *testing.T) { type testCase struct { - value string - expected string - err error + value string + expected string + expectedErr string } tests := []testCase{ { @@ -53,8 +53,8 @@ func TestValidateEnv(t *testing.T) { expected: fmt.Sprintf("PATH=%v", os.Getenv("PATH")), }, { - value: "=a", - err: fmt.Errorf("invalid environment variable: =a"), + value: "=a", + expectedErr: "invalid environment variable: =a", }, { value: "PATH=", @@ -89,17 +89,17 @@ func TestValidateEnv(t *testing.T) { expected: "some space after ", }, { - value: "=", - err: fmt.Errorf("invalid environment variable: ="), + value: "=", + expectedErr: "invalid environment variable: =", }, } if runtime.GOOS == "windows" { // Environment variables are case in-sensitive on Windows tests = append(tests, testCase{ - value: "PaTh", - expected: fmt.Sprintf("PaTh=%v", os.Getenv("PATH")), - err: nil, + value: "PaTh", + expected: fmt.Sprintf("PaTh=%v", os.Getenv("PATH")), + expectedErr: "", }) } @@ -108,10 +108,10 @@ func TestValidateEnv(t *testing.T) { t.Run(tc.value, func(t *testing.T) { actual, err := ValidateEnv(tc.value) - if tc.err == nil { + if tc.expectedErr == "" { assert.NilError(t, err) } else { - assert.Error(t, err, tc.err.Error()) + assert.Error(t, err, tc.expectedErr) } assert.Equal(t, actual, tc.expected) }) diff --git a/opts/mount.go b/opts/mount.go index 430b858e8f..3a4ee31a27 100644 --- a/opts/mount.go +++ b/opts/mount.go @@ -165,11 +165,11 @@ func (m *MountOpt) Set(value string) error { } if mount.Type == "" { - return fmt.Errorf("type is required") + return errors.New("type is required") } if mount.Target == "" { - return fmt.Errorf("target is required") + return errors.New("target is required") } if mount.VolumeOptions != nil && mount.Type != mounttypes.TypeVolume { diff --git a/opts/network.go b/opts/network.go index e36ef405d1..413aec7b52 100644 --- a/opts/network.go +++ b/opts/network.go @@ -2,6 +2,7 @@ package opts import ( "encoding/csv" + "errors" "fmt" "regexp" "strings" @@ -83,11 +84,11 @@ func (n *NetworkOpt) Set(value string) error { //nolint:gocyclo } netOpt.DriverOpts[key] = val default: - return fmt.Errorf("invalid field key %s", key) + return errors.New("invalid field key " + key) } } if len(netOpt.Target) == 0 { - return fmt.Errorf("network name/id is not specified") + return errors.New("network name/id is not specified") } } else { netOpt.Target = value @@ -126,7 +127,7 @@ func parseDriverOpt(driverOpt string) (string, string, error) { // TODO(thaJeztah): should value be converted to lowercase as well, or only the key? key, value, ok := strings.Cut(strings.ToLower(driverOpt), "=") if !ok || key == "" { - return "", "", fmt.Errorf("invalid key value pair format in driver options") + return "", "", errors.New("invalid key value pair format in driver options") } key = strings.TrimSpace(key) value = strings.TrimSpace(value) diff --git a/opts/opts.go b/opts/opts.go index 80de16052c..254d7eb128 100644 --- a/opts/opts.go +++ b/opts/opts.go @@ -401,7 +401,7 @@ func ParseCPUs(value string) (int64, error) { } nano := cpu.Mul(cpu, big.NewRat(1e9, 1)) if !nano.IsInt() { - return 0, fmt.Errorf("value is too precise") + return 0, errors.New("value is too precise") } return nano.Num().Int64(), nil } @@ -409,14 +409,14 @@ func ParseCPUs(value string) (int64, error) { // ParseLink parses and validates the specified string as a link format (name:alias) func ParseLink(val string) (string, string, error) { if val == "" { - return "", "", fmt.Errorf("empty string specified for links") + return "", "", errors.New("empty string specified for links") } // We expect two parts, but restrict to three to allow detecting invalid formats. arr := strings.SplitN(val, ":", 3) // TODO(thaJeztah): clean up this logic!! if len(arr) > 2 { - return "", "", fmt.Errorf("bad format for links: %s", val) + return "", "", errors.New("bad format for links: " + val) } // TODO(thaJeztah): this should trim the "/" prefix as well?? if len(arr) == 1 { diff --git a/opts/parse.go b/opts/parse.go index 381648fe73..584b55ef61 100644 --- a/opts/parse.go +++ b/opts/parse.go @@ -1,7 +1,7 @@ package opts import ( - "fmt" + "errors" "os" "strconv" "strings" @@ -81,12 +81,12 @@ func ParseRestartPolicy(policy string) (container.RestartPolicy, error) { p := container.RestartPolicy{} k, v, ok := strings.Cut(policy, ":") if ok && k == "" { - return container.RestartPolicy{}, fmt.Errorf("invalid restart policy format: no policy provided before colon") + return container.RestartPolicy{}, errors.New("invalid restart policy format: no policy provided before colon") } if v != "" { count, err := strconv.Atoi(v) if err != nil { - return container.RestartPolicy{}, fmt.Errorf("invalid restart policy format: maximum retry count must be an integer") + return container.RestartPolicy{}, errors.New("invalid restart policy format: maximum retry count must be an integer") } p.MaximumRetryCount = count } diff --git a/opts/port.go b/opts/port.go index fe41cdd288..2f2aa329c8 100644 --- a/opts/port.go +++ b/opts/port.go @@ -2,6 +2,7 @@ package opts import ( "encoding/csv" + "errors" "fmt" "net" "regexp" @@ -102,7 +103,7 @@ func (p *PortOpt) Set(value string) error { for _, portBindings := range portBindingMap { for _, portBinding := range portBindings { if portBinding.HostIP != "" { - return fmt.Errorf("hostip is not supported") + return errors.New("hostip is not supported") } } } diff --git a/opts/secret.go b/opts/secret.go index 750dbe4f30..09d2b2b3be 100644 --- a/opts/secret.go +++ b/opts/secret.go @@ -2,6 +2,7 @@ package opts import ( "encoding/csv" + "errors" "fmt" "os" "strconv" @@ -62,12 +63,12 @@ func (o *SecretOpt) Set(value string) error { options.File.Mode = os.FileMode(m) default: - return fmt.Errorf("invalid field in secret request: %s", key) + return errors.New("invalid field in secret request: " + key) } } if options.SecretName == "" { - return fmt.Errorf("source is required") + return errors.New("source is required") } if options.File.Name == "" { options.File.Name = options.SecretName