Skip to content

Commit 121b2c9

Browse files
committed
cmd/dockerd: use stdlib errors
This package is not imported externally, and we don't need the added functionality of pkg/errors here, so use stdlib errors. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 0f75059 commit 121b2c9

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

cmd/docker/aliases.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package main
22

33
import (
4+
"fmt"
45
"os"
56
"strings"
67

78
pluginmanager "github.com/docker/cli/cli-plugins/manager"
89
"github.com/docker/cli/cli/command"
9-
"github.com/pkg/errors"
1010
"github.com/spf13/cobra"
1111
)
1212

@@ -26,11 +26,11 @@ func processAliases(dockerCli command.Cli, cmd *cobra.Command, args, osArgs []st
2626

2727
for k, v := range aliasMap {
2828
if _, ok := allowedAliases[k]; !ok {
29-
return args, osArgs, envs, errors.Errorf("not allowed to alias %q (allowed: %#v)", k, allowedAliases)
29+
return args, osArgs, envs, fmt.Errorf("not allowed to alias %q (allowed: %#v)", k, allowedAliases)
3030
}
3131
if c, _, err := cmd.Find(strings.Split(v, " ")); err == nil {
3232
if !pluginmanager.IsPluginCommand(c) {
33-
return args, osArgs, envs, errors.Errorf("not allowed to alias with builtin %q as target", v)
33+
return args, osArgs, envs, fmt.Errorf("not allowed to alias with builtin %q as target", v)
3434
}
3535
}
3636
aliases = append(aliases, [2][]string{{k}, {v}})

cmd/docker/builder.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"errors"
45
"fmt"
56
"io"
67
"os"
@@ -11,7 +12,6 @@ import (
1112
"github.com/docker/cli/cli-plugins/metadata"
1213
"github.com/docker/cli/cli/command"
1314
"github.com/docker/docker/api/types"
14-
"github.com/pkg/errors"
1515
"github.com/spf13/cobra"
1616
"github.com/spf13/pflag"
1717
)
@@ -51,7 +51,7 @@ func processBuilder(dockerCli command.Cli, cmd *cobra.Command, args, osargs []st
5151
if v := os.Getenv("DOCKER_BUILDKIT"); v != "" {
5252
enabled, err := strconv.ParseBool(v)
5353
if err != nil {
54-
return args, osargs, nil, errors.Wrap(err, "DOCKER_BUILDKIT environment variable expects boolean value")
54+
return args, osargs, nil, fmt.Errorf("DOCKER_BUILDKIT environment variable expects boolean value: %w", err)
5555
}
5656
if !enabled {
5757
buildKitDisabled = true

cmd/docker/docker.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"io"
78
"os"
@@ -21,7 +22,6 @@ import (
2122
platformsignals "github.com/docker/cli/cmd/docker/internal/signals"
2223
"github.com/docker/docker/api/types/versions"
2324
"github.com/docker/docker/errdefs"
24-
"github.com/pkg/errors"
2525
"github.com/sirupsen/logrus"
2626
"github.com/spf13/cobra"
2727
"github.com/spf13/pflag"
@@ -203,7 +203,7 @@ func setupHelpCommand(dockerCli command.Cli, rootCmd, helpCmd *cobra.Command) {
203203
return helpcmd.Run()
204204
}
205205
if !pluginmanager.IsNotFound(err) {
206-
return errors.Errorf("unknown help topic: %v", strings.Join(args, " "))
206+
return fmt.Errorf("unknown help topic: %v", strings.Join(args, " "))
207207
}
208208
}
209209
if origRunE != nil {
@@ -593,7 +593,7 @@ func isSupported(cmd *cobra.Command, details versionDetails) error {
593593
}
594594

595595
func areFlagsSupported(cmd *cobra.Command, details versionDetails) error {
596-
errs := []string{}
596+
var errs []error
597597

598598
cmd.Flags().VisitAll(func(f *pflag.Flag) {
599599
if !f.Changed || len(f.Annotations) == 0 {
@@ -612,22 +612,19 @@ func areFlagsSupported(cmd *cobra.Command, details versionDetails) error {
612612
return
613613
}
614614
if _, ok := f.Annotations["ostype"]; ok && !isOSTypeSupported(f, details.ServerInfo().OSType) {
615-
errs = append(errs, fmt.Sprintf(
615+
errs = append(errs, fmt.Errorf(
616616
`"--%s" is only supported on a Docker daemon running on %s, but the Docker daemon is running on %s`,
617617
f.Name,
618618
getFlagAnnotation(f, "ostype"), details.ServerInfo().OSType),
619619
)
620620
return
621621
}
622622
if _, ok := f.Annotations["experimental"]; ok && !details.ServerInfo().HasExperimental {
623-
errs = append(errs, fmt.Sprintf(`"--%s" is only supported on a Docker daemon with experimental features enabled`, f.Name))
623+
errs = append(errs, fmt.Errorf(`"--%s" is only supported on a Docker daemon with experimental features enabled`, f.Name))
624624
}
625625
// buildkit-specific flags are noop when buildkit is not enabled, so we do not add an error in that case
626626
})
627-
if len(errs) > 0 {
628-
return errors.New(strings.Join(errs, "\n"))
629-
}
630-
return nil
627+
return errors.Join(errs...)
631628
}
632629

633630
// Check recursively so that, e.g., `docker stack ls` returns the same output as `docker stack`

cmd/docker/docker_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"bytes"
55
"context"
6+
"errors"
67
"io"
78
"os"
89
"syscall"
@@ -12,7 +13,6 @@ import (
1213
"github.com/docker/cli/cli/command"
1314
"github.com/docker/cli/cli/debug"
1415
platformsignals "github.com/docker/cli/cmd/docker/internal/signals"
15-
"github.com/pkg/errors"
1616
"github.com/sirupsen/logrus"
1717
"gotest.tools/v3/assert"
1818
is "gotest.tools/v3/assert/cmp"

0 commit comments

Comments
 (0)