Skip to content

Commit fecb1b2

Browse files
authored
Merge pull request #4282 from thaJeztah/remove_uses_of_client_IsErrNotFound
replace uses of client.IsErrNotFound for errdefs.IsNotFound
2 parents 761d973 + 2fc30fd commit fecb1b2

9 files changed

Lines changed: 20 additions & 22 deletions

File tree

cli/command/container/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/docker/docker/api/types"
1919
"github.com/docker/docker/api/types/container"
2020
"github.com/docker/docker/api/types/versions"
21-
apiclient "github.com/docker/docker/client"
21+
"github.com/docker/docker/errdefs"
2222
"github.com/docker/docker/pkg/jsonmessage"
2323
specs "github.com/opencontainers/image-spec/specs-go/v1"
2424
"github.com/pkg/errors"
@@ -255,7 +255,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
255255
response, err := dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, platform, opts.name)
256256
if err != nil {
257257
// Pull image if it does not exist locally and we have the PullImageMissing option. Default behavior.
258-
if apiclient.IsErrNotFound(err) && namedRef != nil && opts.pull == PullImageMissing {
258+
if errdefs.IsNotFound(err) && namedRef != nil && opts.pull == PullImageMissing {
259259
if !opts.quiet {
260260
// we don't want to write to stdout anything apart from container.ID
261261
fmt.Fprintf(dockerCli.Err(), "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef))

cli/command/container/create_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,5 +350,5 @@ func TestCreateContainerWithProxyConfig(t *testing.T) {
350350

351351
type fakeNotFound struct{}
352352

353-
func (f fakeNotFound) NotFound() bool { return true }
354-
func (f fakeNotFound) Error() string { return "error fake not found" }
353+
func (f fakeNotFound) NotFound() {}
354+
func (f fakeNotFound) Error() string { return "error fake not found" }

cli/command/image/remove.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/docker/cli/cli"
99
"github.com/docker/cli/cli/command"
1010
"github.com/docker/docker/api/types"
11-
apiclient "github.com/docker/docker/client"
11+
"github.com/docker/docker/errdefs"
1212
"github.com/pkg/errors"
1313
"github.com/spf13/cobra"
1414
)
@@ -63,7 +63,7 @@ func runRemove(dockerCli command.Cli, opts removeOptions, images []string) error
6363
for _, img := range images {
6464
dels, err := client.ImageRemove(ctx, img, options)
6565
if err != nil {
66-
if !apiclient.IsErrNotFound(err) {
66+
if !errdefs.IsNotFound(err) {
6767
fatalErr = true
6868
}
6969
errs = append(errs, err.Error())

cli/command/image/remove_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ func (n notFound) Error() string {
2121
return fmt.Sprintf("Error: No such image: %s", n.imageID)
2222
}
2323

24-
func (n notFound) NotFound() bool {
25-
return true
26-
}
24+
func (n notFound) NotFound() {}
2725

2826
func TestNewRemoveCommandAlias(t *testing.T) {
2927
cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}))

cli/command/service/inspect.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/docker/cli/cli/command/formatter"
1010
flagsHelper "github.com/docker/cli/cli/flags"
1111
"github.com/docker/docker/api/types"
12-
apiclient "github.com/docker/docker/client"
12+
"github.com/docker/docker/errdefs"
1313
"github.com/pkg/errors"
1414
"github.com/spf13/cobra"
1515
)
@@ -57,15 +57,15 @@ func runInspect(dockerCli command.Cli, opts inspectOptions) error {
5757
getRef := func(ref string) (interface{}, []byte, error) {
5858
// Service inspect shows defaults values in empty fields.
5959
service, _, err := client.ServiceInspectWithRaw(ctx, ref, types.ServiceInspectOptions{InsertDefaults: true})
60-
if err == nil || !apiclient.IsErrNotFound(err) {
60+
if err == nil || !errdefs.IsNotFound(err) {
6161
return service, nil, err
6262
}
6363
return nil, nil, errors.Errorf("Error: no such service: %s", ref)
6464
}
6565

6666
getNetwork := func(ref string) (interface{}, []byte, error) {
6767
network, _, err := client.NetworkInspectWithRaw(ctx, ref, types.NetworkInspectOptions{Scope: "swarm"})
68-
if err == nil || !apiclient.IsErrNotFound(err) {
68+
if err == nil || !errdefs.IsNotFound(err) {
6969
return network, nil, err
7070
}
7171
return nil, nil, errors.Errorf("Error: no such network: %s", ref)

cli/command/service/logs.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/docker/docker/api/types"
1717
"github.com/docker/docker/api/types/swarm"
1818
"github.com/docker/docker/client"
19+
"github.com/docker/docker/errdefs"
1920
"github.com/docker/docker/pkg/stdcopy"
2021
"github.com/docker/docker/pkg/stringid"
2122
"github.com/pkg/errors"
@@ -99,12 +100,12 @@ func runLogs(dockerCli command.Cli, opts *logsOptions) error {
99100
service, _, err := cli.ServiceInspectWithRaw(ctx, opts.target, types.ServiceInspectOptions{})
100101
if err != nil {
101102
// if it's any error other than service not found, it's Real
102-
if !client.IsErrNotFound(err) {
103+
if !errdefs.IsNotFound(err) {
103104
return err
104105
}
105106
task, _, err := cli.TaskInspectWithRaw(ctx, opts.target)
106107
if err != nil {
107-
if client.IsErrNotFound(err) {
108+
if errdefs.IsNotFound(err) {
108109
// if the task isn't found, rewrite the error to be clear
109110
// that we looked for services AND tasks and found none
110111
err = fmt.Errorf("no such task or service: %v", opts.target)

cli/command/stack/swarm/deploy_composefile.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/docker/docker/api/types/container"
1313
"github.com/docker/docker/api/types/swarm"
1414
apiclient "github.com/docker/docker/client"
15+
"github.com/docker/docker/errdefs"
1516
"github.com/pkg/errors"
1617
)
1718

@@ -85,7 +86,7 @@ func validateExternalNetworks(ctx context.Context, client apiclient.NetworkAPICl
8586
}
8687
network, err := client.NetworkInspect(ctx, networkName, types.NetworkInspectOptions{})
8788
switch {
88-
case apiclient.IsErrNotFound(err):
89+
case errdefs.IsNotFound(err):
8990
return errors.Errorf("network %q is declared as external, but could not be found. You need to create a swarm-scoped network before the stack is deployed", networkName)
9091
case err != nil:
9192
return err
@@ -107,7 +108,7 @@ func createSecrets(ctx context.Context, dockerCli command.Cli, secrets []swarm.S
107108
if err := client.SecretUpdate(ctx, secret.ID, secret.Meta.Version, secretSpec); err != nil {
108109
return errors.Wrapf(err, "failed to update secret %s", secretSpec.Name)
109110
}
110-
case apiclient.IsErrNotFound(err):
111+
case errdefs.IsNotFound(err):
111112
// secret does not exist, then we create a new one.
112113
fmt.Fprintf(dockerCli.Out(), "Creating secret %s\n", secretSpec.Name)
113114
if _, err := client.SecretCreate(ctx, secretSpec); err != nil {
@@ -131,7 +132,7 @@ func createConfigs(ctx context.Context, dockerCli command.Cli, configs []swarm.C
131132
if err := client.ConfigUpdate(ctx, config.ID, config.Meta.Version, configSpec); err != nil {
132133
return errors.Wrapf(err, "failed to update config %s", configSpec.Name)
133134
}
134-
case apiclient.IsErrNotFound(err):
135+
case errdefs.IsNotFound(err):
135136
// config does not exist, then we create a new one.
136137
fmt.Fprintf(dockerCli.Out(), "Creating config %s\n", configSpec.Name)
137138
if _, err := client.ConfigCreate(ctx, configSpec); err != nil {

cli/command/stack/swarm/deploy_composefile_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ type notFound struct {
1414
error
1515
}
1616

17-
func (n notFound) NotFound() bool {
18-
return true
19-
}
17+
func (n notFound) NotFound() {}
2018

2119
func TestValidateExternalNetworks(t *testing.T) {
2220
testcases := []struct {

cli/command/system/inspect.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"github.com/docker/cli/cli/command/inspect"
1111
flagsHelper "github.com/docker/cli/cli/flags"
1212
"github.com/docker/docker/api/types"
13-
apiclient "github.com/docker/docker/client"
13+
"github.com/docker/docker/errdefs"
1414
"github.com/pkg/errors"
1515
"github.com/spf13/cobra"
1616
)
@@ -213,7 +213,7 @@ func inspectAll(ctx context.Context, dockerCli command.Cli, getSize bool, typeCo
213213
}
214214

215215
func isErrSkippable(err error) bool {
216-
return apiclient.IsErrNotFound(err) ||
216+
return errdefs.IsNotFound(err) ||
217217
strings.Contains(err.Error(), "not supported") ||
218218
strings.Contains(err.Error(), "invalid reference format")
219219
}

0 commit comments

Comments
 (0)