diff --git a/cli/command/cli_options.go b/cli/command/cli_options.go index ff6506f042..5d0a8ee3a6 100644 --- a/cli/command/cli_options.go +++ b/cli/command/cli_options.go @@ -11,7 +11,6 @@ import ( "github.com/docker/cli/cli/streams" "github.com/docker/docker/client" - "github.com/docker/docker/errdefs" "github.com/moby/term" "github.com/pkg/errors" ) @@ -178,7 +177,7 @@ func withCustomHeadersFromEnv() client.Opt { csvReader := csv.NewReader(strings.NewReader(value)) fields, err := csvReader.Read() if err != nil { - return errdefs.InvalidParameter(errors.Errorf( + return invalidParameter(errors.Errorf( "failed to parse custom headers from %s environment variable: value must be formatted as comma-separated key=value pairs", envOverrideHTTPHeaders, )) @@ -195,7 +194,7 @@ func withCustomHeadersFromEnv() client.Opt { k = strings.TrimSpace(k) if k == "" { - return errdefs.InvalidParameter(errors.Errorf( + return invalidParameter(errors.Errorf( `failed to set custom headers from %s environment variable: value contains a key=value pair with an empty key: '%s'`, envOverrideHTTPHeaders, kv, )) @@ -206,7 +205,7 @@ func withCustomHeadersFromEnv() client.Opt { // from an environment variable with the same name). In the meantime, // produce an error to prevent users from depending on this. if !hasValue { - return errdefs.InvalidParameter(errors.Errorf( + return invalidParameter(errors.Errorf( `failed to set custom headers from %s environment variable: missing "=" in key=value pair: '%s'`, envOverrideHTTPHeaders, kv, )) diff --git a/cli/command/defaultcontextstore.go b/cli/command/defaultcontextstore.go index 496233ae18..9b49b3af2a 100644 --- a/cli/command/defaultcontextstore.go +++ b/cli/command/defaultcontextstore.go @@ -7,7 +7,6 @@ import ( "github.com/docker/cli/cli/context/docker" "github.com/docker/cli/cli/context/store" cliflags "github.com/docker/cli/cli/flags" - "github.com/docker/docker/errdefs" "github.com/pkg/errors" ) @@ -117,7 +116,7 @@ func (s *ContextStoreWithDefault) List() ([]store.Metadata, error) { // CreateOrUpdate is not allowed for the default context and fails func (s *ContextStoreWithDefault) CreateOrUpdate(meta store.Metadata) error { if meta.Name == DefaultContextName { - return errdefs.InvalidParameter(errors.New("default context cannot be created nor updated")) + return invalidParameter(errors.New("default context cannot be created nor updated")) } return s.Store.CreateOrUpdate(meta) } @@ -125,7 +124,7 @@ func (s *ContextStoreWithDefault) CreateOrUpdate(meta store.Metadata) error { // Remove is not allowed for the default context and fails func (s *ContextStoreWithDefault) Remove(name string) error { if name == DefaultContextName { - return errdefs.InvalidParameter(errors.New("default context cannot be removed")) + return invalidParameter(errors.New("default context cannot be removed")) } return s.Store.Remove(name) } @@ -145,7 +144,7 @@ func (s *ContextStoreWithDefault) GetMetadata(name string) (store.Metadata, erro // ResetTLSMaterial is not implemented for default context and fails func (s *ContextStoreWithDefault) ResetTLSMaterial(name string, data *store.ContextTLSData) error { if name == DefaultContextName { - return errdefs.InvalidParameter(errors.New("default context cannot be edited")) + return invalidParameter(errors.New("default context cannot be edited")) } return s.Store.ResetTLSMaterial(name, data) } @@ -153,7 +152,7 @@ func (s *ContextStoreWithDefault) ResetTLSMaterial(name string, data *store.Cont // ResetEndpointTLSMaterial is not implemented for default context and fails func (s *ContextStoreWithDefault) ResetEndpointTLSMaterial(contextName string, endpointName string, data *store.EndpointTLSData) error { if contextName == DefaultContextName { - return errdefs.InvalidParameter(errors.New("default context cannot be edited")) + return invalidParameter(errors.New("default context cannot be edited")) } return s.Store.ResetEndpointTLSMaterial(contextName, endpointName, data) } @@ -186,7 +185,7 @@ func (s *ContextStoreWithDefault) GetTLSData(contextName, endpointName, fileName return nil, err } if defaultContext.TLS.Endpoints[endpointName].Files[fileName] == nil { - return nil, errdefs.NotFound(errors.Errorf("TLS data for %s/%s/%s does not exist", DefaultContextName, endpointName, fileName)) + return nil, notFound(errors.Errorf("TLS data for %s/%s/%s does not exist", DefaultContextName, endpointName, fileName)) } return defaultContext.TLS.Endpoints[endpointName].Files[fileName], nil } diff --git a/cli/command/utils.go b/cli/command/utils.go index 08f96cae36..ab64ef8fc1 100644 --- a/cli/command/utils.go +++ b/cli/command/utils.go @@ -151,3 +151,22 @@ func ValidateOutputPathFileMode(fileMode os.FileMode) error { } return nil } + +func invalidParameter(err error) error { + return invalidParameterErr{err} +} + +type invalidParameterErr struct{ error } + +func (invalidParameterErr) InvalidParameter() {} + +func notFound(err error) error { + return notFoundErr{err} +} + +type notFoundErr struct{ error } + +func (notFoundErr) NotFound() {} +func (e notFoundErr) Unwrap() error { + return e.error +}