mirror of https://github.com/docker/cli.git
replace uses of client.IsErrNotFound for errdefs.IsNotFound
None of the client will return the old error-types, so there's no need to keep the compatibility code. We can consider deprecating this function in favor of the errdefs equivalent this. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
537b88dab9
commit
2fc30fd456
|
@ -18,7 +18,7 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/api/types/versions"
|
"github.com/docker/docker/api/types/versions"
|
||||||
apiclient "github.com/docker/docker/client"
|
"github.com/docker/docker/errdefs"
|
||||||
"github.com/docker/docker/pkg/jsonmessage"
|
"github.com/docker/docker/pkg/jsonmessage"
|
||||||
specs "github.com/opencontainers/image-spec/specs-go/v1"
|
specs "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -255,7 +255,7 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
|
||||||
response, err := dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, platform, opts.name)
|
response, err := dockerCli.Client().ContainerCreate(ctx, config, hostConfig, networkingConfig, platform, opts.name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Pull image if it does not exist locally and we have the PullImageMissing option. Default behavior.
|
// Pull image if it does not exist locally and we have the PullImageMissing option. Default behavior.
|
||||||
if apiclient.IsErrNotFound(err) && namedRef != nil && opts.pull == PullImageMissing {
|
if errdefs.IsNotFound(err) && namedRef != nil && opts.pull == PullImageMissing {
|
||||||
if !opts.quiet {
|
if !opts.quiet {
|
||||||
// we don't want to write to stdout anything apart from container.ID
|
// we don't want to write to stdout anything apart from container.ID
|
||||||
fmt.Fprintf(dockerCli.Err(), "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef))
|
fmt.Fprintf(dockerCli.Err(), "Unable to find image '%s' locally\n", reference.FamiliarString(namedRef))
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/docker/cli/cli"
|
"github.com/docker/cli/cli"
|
||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
apiclient "github.com/docker/docker/client"
|
"github.com/docker/docker/errdefs"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
@ -63,7 +63,7 @@ func runRemove(dockerCli command.Cli, opts removeOptions, images []string) error
|
||||||
for _, img := range images {
|
for _, img := range images {
|
||||||
dels, err := client.ImageRemove(ctx, img, options)
|
dels, err := client.ImageRemove(ctx, img, options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !apiclient.IsErrNotFound(err) {
|
if !errdefs.IsNotFound(err) {
|
||||||
fatalErr = true
|
fatalErr = true
|
||||||
}
|
}
|
||||||
errs = append(errs, err.Error())
|
errs = append(errs, err.Error())
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"github.com/docker/cli/cli/command/formatter"
|
"github.com/docker/cli/cli/command/formatter"
|
||||||
flagsHelper "github.com/docker/cli/cli/flags"
|
flagsHelper "github.com/docker/cli/cli/flags"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
apiclient "github.com/docker/docker/client"
|
"github.com/docker/docker/errdefs"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
@ -57,7 +57,7 @@ func runInspect(dockerCli command.Cli, opts inspectOptions) error {
|
||||||
getRef := func(ref string) (interface{}, []byte, error) {
|
getRef := func(ref string) (interface{}, []byte, error) {
|
||||||
// Service inspect shows defaults values in empty fields.
|
// Service inspect shows defaults values in empty fields.
|
||||||
service, _, err := client.ServiceInspectWithRaw(ctx, ref, types.ServiceInspectOptions{InsertDefaults: true})
|
service, _, err := client.ServiceInspectWithRaw(ctx, ref, types.ServiceInspectOptions{InsertDefaults: true})
|
||||||
if err == nil || !apiclient.IsErrNotFound(err) {
|
if err == nil || !errdefs.IsNotFound(err) {
|
||||||
return service, nil, err
|
return service, nil, err
|
||||||
}
|
}
|
||||||
return nil, nil, errors.Errorf("Error: no such service: %s", ref)
|
return nil, nil, errors.Errorf("Error: no such service: %s", ref)
|
||||||
|
@ -65,7 +65,7 @@ func runInspect(dockerCli command.Cli, opts inspectOptions) error {
|
||||||
|
|
||||||
getNetwork := func(ref string) (interface{}, []byte, error) {
|
getNetwork := func(ref string) (interface{}, []byte, error) {
|
||||||
network, _, err := client.NetworkInspectWithRaw(ctx, ref, types.NetworkInspectOptions{Scope: "swarm"})
|
network, _, err := client.NetworkInspectWithRaw(ctx, ref, types.NetworkInspectOptions{Scope: "swarm"})
|
||||||
if err == nil || !apiclient.IsErrNotFound(err) {
|
if err == nil || !errdefs.IsNotFound(err) {
|
||||||
return network, nil, err
|
return network, nil, err
|
||||||
}
|
}
|
||||||
return nil, nil, errors.Errorf("Error: no such network: %s", ref)
|
return nil, nil, errors.Errorf("Error: no such network: %s", ref)
|
||||||
|
|
|
@ -16,6 +16,7 @@ import (
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"github.com/docker/docker/client"
|
"github.com/docker/docker/client"
|
||||||
|
"github.com/docker/docker/errdefs"
|
||||||
"github.com/docker/docker/pkg/stdcopy"
|
"github.com/docker/docker/pkg/stdcopy"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
@ -99,12 +100,12 @@ func runLogs(dockerCli command.Cli, opts *logsOptions) error {
|
||||||
service, _, err := cli.ServiceInspectWithRaw(ctx, opts.target, types.ServiceInspectOptions{})
|
service, _, err := cli.ServiceInspectWithRaw(ctx, opts.target, types.ServiceInspectOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// if it's any error other than service not found, it's Real
|
// if it's any error other than service not found, it's Real
|
||||||
if !client.IsErrNotFound(err) {
|
if !errdefs.IsNotFound(err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
task, _, err := cli.TaskInspectWithRaw(ctx, opts.target)
|
task, _, err := cli.TaskInspectWithRaw(ctx, opts.target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if client.IsErrNotFound(err) {
|
if errdefs.IsNotFound(err) {
|
||||||
// if the task isn't found, rewrite the error to be clear
|
// if the task isn't found, rewrite the error to be clear
|
||||||
// that we looked for services AND tasks and found none
|
// that we looked for services AND tasks and found none
|
||||||
err = fmt.Errorf("no such task or service: %v", opts.target)
|
err = fmt.Errorf("no such task or service: %v", opts.target)
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"github.com/docker/docker/api/types/container"
|
"github.com/docker/docker/api/types/container"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
apiclient "github.com/docker/docker/client"
|
apiclient "github.com/docker/docker/client"
|
||||||
|
"github.com/docker/docker/errdefs"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -85,7 +86,7 @@ func validateExternalNetworks(ctx context.Context, client apiclient.NetworkAPICl
|
||||||
}
|
}
|
||||||
network, err := client.NetworkInspect(ctx, networkName, types.NetworkInspectOptions{})
|
network, err := client.NetworkInspect(ctx, networkName, types.NetworkInspectOptions{})
|
||||||
switch {
|
switch {
|
||||||
case apiclient.IsErrNotFound(err):
|
case errdefs.IsNotFound(err):
|
||||||
return errors.Errorf("network %q is declared as external, but could not be found. You need to create a swarm-scoped network before the stack is deployed", networkName)
|
return errors.Errorf("network %q is declared as external, but could not be found. You need to create a swarm-scoped network before the stack is deployed", networkName)
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return err
|
return err
|
||||||
|
@ -107,7 +108,7 @@ func createSecrets(ctx context.Context, dockerCli command.Cli, secrets []swarm.S
|
||||||
if err := client.SecretUpdate(ctx, secret.ID, secret.Meta.Version, secretSpec); err != nil {
|
if err := client.SecretUpdate(ctx, secret.ID, secret.Meta.Version, secretSpec); err != nil {
|
||||||
return errors.Wrapf(err, "failed to update secret %s", secretSpec.Name)
|
return errors.Wrapf(err, "failed to update secret %s", secretSpec.Name)
|
||||||
}
|
}
|
||||||
case apiclient.IsErrNotFound(err):
|
case errdefs.IsNotFound(err):
|
||||||
// secret does not exist, then we create a new one.
|
// secret does not exist, then we create a new one.
|
||||||
fmt.Fprintf(dockerCli.Out(), "Creating secret %s\n", secretSpec.Name)
|
fmt.Fprintf(dockerCli.Out(), "Creating secret %s\n", secretSpec.Name)
|
||||||
if _, err := client.SecretCreate(ctx, secretSpec); err != nil {
|
if _, err := client.SecretCreate(ctx, secretSpec); err != nil {
|
||||||
|
@ -131,7 +132,7 @@ func createConfigs(ctx context.Context, dockerCli command.Cli, configs []swarm.C
|
||||||
if err := client.ConfigUpdate(ctx, config.ID, config.Meta.Version, configSpec); err != nil {
|
if err := client.ConfigUpdate(ctx, config.ID, config.Meta.Version, configSpec); err != nil {
|
||||||
return errors.Wrapf(err, "failed to update config %s", configSpec.Name)
|
return errors.Wrapf(err, "failed to update config %s", configSpec.Name)
|
||||||
}
|
}
|
||||||
case apiclient.IsErrNotFound(err):
|
case errdefs.IsNotFound(err):
|
||||||
// config does not exist, then we create a new one.
|
// config does not exist, then we create a new one.
|
||||||
fmt.Fprintf(dockerCli.Out(), "Creating config %s\n", configSpec.Name)
|
fmt.Fprintf(dockerCli.Out(), "Creating config %s\n", configSpec.Name)
|
||||||
if _, err := client.ConfigCreate(ctx, configSpec); err != nil {
|
if _, err := client.ConfigCreate(ctx, configSpec); err != nil {
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"github.com/docker/cli/cli/command/inspect"
|
"github.com/docker/cli/cli/command/inspect"
|
||||||
flagsHelper "github.com/docker/cli/cli/flags"
|
flagsHelper "github.com/docker/cli/cli/flags"
|
||||||
"github.com/docker/docker/api/types"
|
"github.com/docker/docker/api/types"
|
||||||
apiclient "github.com/docker/docker/client"
|
"github.com/docker/docker/errdefs"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
@ -213,7 +213,7 @@ func inspectAll(ctx context.Context, dockerCli command.Cli, getSize bool, typeCo
|
||||||
}
|
}
|
||||||
|
|
||||||
func isErrSkippable(err error) bool {
|
func isErrSkippable(err error) bool {
|
||||||
return apiclient.IsErrNotFound(err) ||
|
return errdefs.IsNotFound(err) ||
|
||||||
strings.Contains(err.Error(), "not supported") ||
|
strings.Contains(err.Error(), "not supported") ||
|
||||||
strings.Contains(err.Error(), "invalid reference format")
|
strings.Contains(err.Error(), "invalid reference format")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue