Skip to content

Commit 557cabb

Browse files
committed
switch to github.com/containerd/errdefs for error-matching
replace uses of docker/errdefs.IsXXX utilities with their containerd/errdefs equivalent. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent c108da5 commit 557cabb

File tree

24 files changed

+843
-42
lines changed

24 files changed

+843
-42
lines changed

cli/command/container/create.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"path"
1212
"strings"
1313

14+
cerrdefs "github.com/containerd/errdefs"
1415
"github.com/containerd/platforms"
1516
"github.com/distribution/reference"
1617
"github.com/docker/cli/cli"
@@ -342,7 +343,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
342343
response, err := dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, platform, options.name)
343344
if err != nil {
344345
// Pull image if it does not exist locally and we have the PullImageMissing option. Default behavior.
345-
if errdefs.IsNotFound(err) && namedRef != nil && options.pull == PullImageMissing {
346+
if cerrdefs.IsNotFound(err) && namedRef != nil && options.pull == PullImageMissing {
346347
if !options.quiet {
347348
// we don't want to write to stdout anything apart from container.ID
348349
_, _ = fmt.Fprintf(dockerCli.Err(), "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef))

cli/command/container/rm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import (
66
"fmt"
77
"strings"
88

9+
cerrdefs "github.com/containerd/errdefs"
910
"github.com/docker/cli/cli"
1011
"github.com/docker/cli/cli/command"
1112
"github.com/docker/cli/cli/command/completion"
1213
"github.com/docker/docker/api/types/container"
13-
"github.com/docker/docker/errdefs"
1414
"github.com/spf13/cobra"
1515
)
1616

@@ -67,7 +67,7 @@ func runRm(ctx context.Context, dockerCLI command.Cli, opts *rmOptions) error {
6767
var errs []error
6868
for _, name := range opts.containers {
6969
if err := <-errChan; err != nil {
70-
if opts.force && errdefs.IsNotFound(err) {
70+
if opts.force && cerrdefs.IsNotFound(err) {
7171
_, _ = fmt.Fprintln(dockerCLI.Err(), err)
7272
continue
7373
}

cli/command/context/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ import (
77
"bytes"
88
"fmt"
99

10+
cerrdefs "github.com/containerd/errdefs"
1011
"github.com/docker/cli/cli"
1112
"github.com/docker/cli/cli/command"
1213
"github.com/docker/cli/cli/command/completion"
1314
"github.com/docker/cli/cli/command/formatter/tabwriter"
1415
"github.com/docker/cli/cli/context/docker"
1516
"github.com/docker/cli/cli/context/store"
16-
"github.com/docker/docker/errdefs"
1717
"github.com/pkg/errors"
1818
"github.com/spf13/cobra"
1919
)
@@ -122,7 +122,7 @@ func checkContextNameForCreation(s store.Reader, name string) error {
122122
if err := store.ValidateContextName(name); err != nil {
123123
return err
124124
}
125-
if _, err := s.GetMetadata(name); !errdefs.IsNotFound(err) {
125+
if _, err := s.GetMetadata(name); !cerrdefs.IsNotFound(err) {
126126
if err != nil {
127127
return errors.Wrap(err, "error while getting existing contexts")
128128
}

cli/command/context/remove_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"path/filepath"
55
"testing"
66

7+
cerrdefs "github.com/containerd/errdefs"
78
"github.com/docker/cli/cli/config"
89
"github.com/docker/cli/cli/config/configfile"
9-
"github.com/docker/docker/errdefs"
1010
"gotest.tools/v3/assert"
1111
is "gotest.tools/v3/assert/cmp"
1212
)
@@ -18,7 +18,7 @@ func TestRemove(t *testing.T) {
1818
_, err := cli.ContextStore().GetMetadata("current")
1919
assert.NilError(t, err)
2020
_, err = cli.ContextStore().GetMetadata("other")
21-
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
21+
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
2222
}
2323

2424
func TestRemoveNotAContext(t *testing.T) {

cli/command/context/use_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
"runtime"
1010
"testing"
1111

12+
cerrdefs "github.com/containerd/errdefs"
1213
"github.com/docker/cli/cli/command"
1314
"github.com/docker/cli/cli/config"
1415
"github.com/docker/cli/cli/config/configfile"
1516
"github.com/docker/cli/cli/flags"
16-
"github.com/docker/docker/errdefs"
1717
"gotest.tools/v3/assert"
1818
is "gotest.tools/v3/assert/cmp"
1919
)
@@ -47,7 +47,7 @@ func TestUse(t *testing.T) {
4747
func TestUseNoExist(t *testing.T) {
4848
cli := makeFakeCli(t)
4949
err := newUseCommand(cli).RunE(nil, []string{"test"})
50-
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
50+
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
5151
}
5252

5353
// TestUseDefaultWithoutConfigFile verifies that the CLI does not create

cli/command/defaultcontextstore_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import (
77
"crypto/rand"
88
"testing"
99

10+
cerrdefs "github.com/containerd/errdefs"
1011
"github.com/docker/cli/cli/config/configfile"
1112
"github.com/docker/cli/cli/context/docker"
1213
"github.com/docker/cli/cli/context/store"
1314
cliflags "github.com/docker/cli/cli/flags"
14-
"github.com/docker/docker/errdefs"
1515
"github.com/docker/go-connections/tlsconfig"
1616
"gotest.tools/v3/assert"
1717
is "gotest.tools/v3/assert/cmp"
@@ -158,21 +158,21 @@ func TestErrCreateDefault(t *testing.T) {
158158
Metadata: testContext{Bar: "baz"},
159159
Name: "default",
160160
})
161-
assert.Check(t, is.ErrorType(err, errdefs.IsInvalidParameter))
161+
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument))
162162
assert.Error(t, err, "default context cannot be created nor updated")
163163
}
164164

165165
func TestErrRemoveDefault(t *testing.T) {
166166
meta := testDefaultMetadata()
167167
s := testStore(t, meta, store.ContextTLSData{})
168168
err := s.Remove("default")
169-
assert.Check(t, is.ErrorType(err, errdefs.IsInvalidParameter))
169+
assert.Check(t, is.ErrorType(err, cerrdefs.IsInvalidArgument))
170170
assert.Error(t, err, "default context cannot be removed")
171171
}
172172

173173
func TestErrTLSDataError(t *testing.T) {
174174
meta := testDefaultMetadata()
175175
s := testStore(t, meta, store.ContextTLSData{})
176176
_, err := s.GetTLSData("default", "noop", "noop")
177-
assert.Check(t, is.ErrorType(err, errdefs.IsNotFound))
177+
assert.Check(t, is.ErrorType(err, cerrdefs.IsNotFound))
178178
}

cli/command/image/remove.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import (
55
"errors"
66
"fmt"
77

8+
cerrdefs "github.com/containerd/errdefs"
89
"github.com/docker/cli/cli"
910
"github.com/docker/cli/cli/command"
1011
"github.com/docker/cli/cli/command/completion"
1112
"github.com/docker/docker/api/types/image"
12-
"github.com/docker/docker/errdefs"
1313
"github.com/spf13/cobra"
1414
)
1515

@@ -64,7 +64,7 @@ func runRemove(ctx context.Context, dockerCLI command.Cli, opts removeOptions, i
6464
for _, img := range images {
6565
dels, err := apiClient.ImageRemove(ctx, img, options)
6666
if err != nil {
67-
if !errdefs.IsNotFound(err) {
67+
if !cerrdefs.IsNotFound(err) {
6868
fatalErr = true
6969
}
7070
errs = append(errs, err)

cli/command/network/remove.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import (
55
"fmt"
66
"strconv"
77

8+
cerrdefs "github.com/containerd/errdefs"
89
"github.com/docker/cli/cli"
910
"github.com/docker/cli/cli/command"
1011
"github.com/docker/cli/cli/command/completion"
1112
"github.com/docker/cli/internal/prompt"
1213
"github.com/docker/docker/api/types/network"
13-
"github.com/docker/docker/errdefs"
1414
"github.com/spf13/cobra"
1515
)
1616

@@ -59,7 +59,7 @@ func runRemove(ctx context.Context, dockerCLI command.Cli, networks []string, op
5959
}
6060
}
6161
if err := apiClient.NetworkRemove(ctx, name); err != nil {
62-
if opts.force && errdefs.IsNotFound(err) {
62+
if opts.force && cerrdefs.IsNotFound(err) {
6363
continue
6464
}
6565
_, _ = fmt.Fprintln(dockerCLI.Err(), err)

cli/command/registry/login.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strconv"
99
"strings"
1010

11+
cerrdefs "github.com/containerd/errdefs"
1112
"github.com/docker/cli/cli"
1213
"github.com/docker/cli/cli/command"
1314
"github.com/docker/cli/cli/command/completion"
@@ -17,7 +18,6 @@ import (
1718
"github.com/docker/cli/internal/tui"
1819
registrytypes "github.com/docker/docker/api/types/registry"
1920
"github.com/docker/docker/client"
20-
"github.com/docker/docker/errdefs"
2121
"github.com/docker/docker/registry"
2222
"github.com/pkg/errors"
2323
"github.com/spf13/cobra"
@@ -156,7 +156,7 @@ func loginWithStoredCredentials(ctx context.Context, dockerCLI command.Cli, auth
156156

157157
response, err := dockerCLI.Client().RegistryLogin(ctx, authConfig)
158158
if err != nil {
159-
if errdefs.IsUnauthorized(err) {
159+
if cerrdefs.IsUnauthorized(err) {
160160
_, _ = fmt.Fprintln(dockerCLI.Err(), "Stored credentials invalid or expired")
161161
} else {
162162
_, _ = fmt.Fprintln(dockerCLI.Err(), "Login did not succeed, error:", err)

cli/command/service/inspect.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import (
77
"context"
88
"strings"
99

10+
cerrdefs "github.com/containerd/errdefs"
1011
"github.com/docker/cli/cli"
1112
"github.com/docker/cli/cli/command"
1213
"github.com/docker/cli/cli/command/completion"
1314
"github.com/docker/cli/cli/command/formatter"
1415
flagsHelper "github.com/docker/cli/cli/flags"
1516
"github.com/docker/docker/api/types"
1617
"github.com/docker/docker/api/types/network"
17-
"github.com/docker/docker/errdefs"
1818
"github.com/pkg/errors"
1919
"github.com/spf13/cobra"
2020
"github.com/spf13/pflag"
@@ -67,15 +67,15 @@ func runInspect(ctx context.Context, dockerCli command.Cli, opts inspectOptions)
6767
getRef := func(ref string) (any, []byte, error) {
6868
// Service inspect shows defaults values in empty fields.
6969
service, _, err := client.ServiceInspectWithRaw(ctx, ref, types.ServiceInspectOptions{InsertDefaults: true})
70-
if err == nil || !errdefs.IsNotFound(err) {
70+
if err == nil || !cerrdefs.IsNotFound(err) {
7171
return service, nil, err
7272
}
7373
return nil, nil, errors.Errorf("Error: no such service: %s", ref)
7474
}
7575

7676
getNetwork := func(ref string) (any, []byte, error) {
7777
nw, _, err := client.NetworkInspectWithRaw(ctx, ref, network.InspectOptions{Scope: "swarm"})
78-
if err == nil || !errdefs.IsNotFound(err) {
78+
if err == nil || !cerrdefs.IsNotFound(err) {
7979
return nw, nil, err
8080
}
8181
return nil, nil, errors.Errorf("Error: no such network: %s", ref)

0 commit comments

Comments
 (0)