From 3382ee3e996208195446d7e4a49353490532ff71 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 16 May 2025 19:42:22 +0200 Subject: [PATCH] cli/command/context: use stdlib errors, remove errdefs uses Signed-off-by: Sebastiaan van Stijn --- cli/command/context/create.go | 8 ++++---- cli/command/context/remove.go | 7 +++++-- cli/command/context/update.go | 3 +-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cli/command/context/create.go b/cli/command/context/create.go index 9a84546c64..313aca142e 100644 --- a/cli/command/context/create.go +++ b/cli/command/context/create.go @@ -5,6 +5,7 @@ package context import ( "bytes" + "errors" "fmt" cerrdefs "github.com/containerd/errdefs" @@ -14,7 +15,6 @@ 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" ) @@ -91,7 +91,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 +124,9 @@ func checkContextNameForCreation(s store.Reader, name string) error { } if _, err := s.GetMetadata(name); !cerrdefs.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/remove.go b/cli/command/context/remove.go index 2630dcd22f..0f73cb1fd7 100644 --- a/cli/command/context/remove.go +++ b/cli/command/context/remove.go @@ -7,7 +7,6 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" - "github.com/docker/docker/errdefs" "github.com/spf13/cobra" ) @@ -75,9 +74,13 @@ 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(fmt.Errorf("context %q does not exist", name)) + return notFoundErr{fmt.Errorf("context %q does not exist", name)} } // Ignore other errors; if relevant, they will produce an error when // performing the actual delete. return nil } + +type notFoundErr struct{ error } + +func (notFoundErr) NotFound() {} diff --git a/cli/command/context/update.go b/cli/command/context/update.go index 16ace82f7c..0995c52ef5 100644 --- a/cli/command/context/update.go +++ b/cli/command/context/update.go @@ -9,7 +9,6 @@ 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" ) @@ -77,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