Skip to content

Commit 3382ee3

Browse files
committed
cli/command/context: use stdlib errors, remove errdefs uses
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent b883976 commit 3382ee3

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

cli/command/context/create.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package context
55

66
import (
77
"bytes"
8+
"errors"
89
"fmt"
910

1011
cerrdefs "github.com/containerd/errdefs"
@@ -14,7 +15,6 @@ import (
1415
"github.com/docker/cli/cli/command/formatter/tabwriter"
1516
"github.com/docker/cli/cli/context/docker"
1617
"github.com/docker/cli/cli/context/store"
17-
"github.com/pkg/errors"
1818
"github.com/spf13/cobra"
1919
)
2020

@@ -91,7 +91,7 @@ func createNewContext(contextStore store.ReaderWriter, o *CreateOptions) error {
9191
}
9292
dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(contextStore, o.Docker)
9393
if err != nil {
94-
return errors.Wrap(err, "unable to create docker endpoint config")
94+
return fmt.Errorf("unable to create docker endpoint config: %w", err)
9595
}
9696
contextMetadata := store.Metadata{
9797
Endpoints: map[string]any{
@@ -124,9 +124,9 @@ func checkContextNameForCreation(s store.Reader, name string) error {
124124
}
125125
if _, err := s.GetMetadata(name); !cerrdefs.IsNotFound(err) {
126126
if err != nil {
127-
return errors.Wrap(err, "error while getting existing contexts")
127+
return fmt.Errorf("error while getting existing contexts: %w", err)
128128
}
129-
return errors.Errorf("context %q already exists", name)
129+
return fmt.Errorf("context %q already exists", name)
130130
}
131131
return nil
132132
}

cli/command/context/remove.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77

88
"github.com/docker/cli/cli"
99
"github.com/docker/cli/cli/command"
10-
"github.com/docker/docker/errdefs"
1110
"github.com/spf13/cobra"
1211
)
1312

@@ -75,9 +74,13 @@ func checkContextExists(dockerCli command.Cli, name string) error {
7574
contextDir := dockerCli.ContextStore().GetStorageInfo(name).MetadataPath
7675
_, err := os.Stat(contextDir)
7776
if os.IsNotExist(err) {
78-
return errdefs.NotFound(fmt.Errorf("context %q does not exist", name))
77+
return notFoundErr{fmt.Errorf("context %q does not exist", name)}
7978
}
8079
// Ignore other errors; if relevant, they will produce an error when
8180
// performing the actual delete.
8281
return nil
8382
}
83+
84+
type notFoundErr struct{ error }
85+
86+
func (notFoundErr) NotFound() {}

cli/command/context/update.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/docker/cli/cli/command/formatter/tabwriter"
1010
"github.com/docker/cli/cli/context/docker"
1111
"github.com/docker/cli/cli/context/store"
12-
"github.com/pkg/errors"
1312
"github.com/spf13/cobra"
1413
)
1514

@@ -77,7 +76,7 @@ func RunUpdate(dockerCLI command.Cli, o *UpdateOptions) error {
7776
if o.Docker != nil {
7877
dockerEP, dockerTLS, err := getDockerEndpointMetadataAndTLS(s, o.Docker)
7978
if err != nil {
80-
return errors.Wrap(err, "unable to create docker endpoint config")
79+
return fmt.Errorf("unable to create docker endpoint config: %w", err)
8180
}
8281
c.Endpoints[docker.DockerEndpoint] = dockerEP
8382
tlsDataToReset[docker.DockerEndpoint] = dockerTLS

0 commit comments

Comments
 (0)