cli/command/context: use stdlib errors, remove errdefs uses

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-05-16 20:18:41 +02:00
parent b883976531
commit 3382ee3e99
3 changed files with 10 additions and 8 deletions
+4 -4
View File
@@ -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
}
+5 -2
View File
@@ -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() {}
+1 -2
View File
@@ -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