Skip to content

Commit

Permalink
cleanup: stop using github.com/pkg/errors
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Hall <[email protected]>
  • Loading branch information
imjasonh committed Dec 4, 2023
1 parent 0acee94 commit 7961d85
Show file tree
Hide file tree
Showing 200 changed files with 550 additions and 636 deletions.
8 changes: 4 additions & 4 deletions cli-plugins/manager/error.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package manager

import (
"github.com/pkg/errors"
"fmt"
)

// pluginError is set as Plugin.Err by NewPlugin if the plugin
Expand Down Expand Up @@ -36,13 +36,13 @@ func (e *pluginError) MarshalText() (text []byte, err error) {
}

// wrapAsPluginError wraps an error in a pluginError with an
// additional message, analogous to errors.Wrapf.
// additional message, analogous to wrapped error.
func wrapAsPluginError(err error, msg string) error {
return &pluginError{cause: errors.Wrap(err, msg)}
return &pluginError{cause: fmt.Errorf(msg+": %w", err)}
}

// NewPluginError creates a new pluginError, analogous to
// errors.Errorf.
func NewPluginError(msg string, args ...any) error {
return &pluginError{cause: errors.Errorf(msg, args...)}
return &pluginError{cause: fmt.Errorf(msg, args...)}
}
9 changes: 5 additions & 4 deletions cli-plugins/manager/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package manager

import (
"encoding/json"
"errors"
"fmt"
"path/filepath"
"regexp"
"strings"

"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -41,14 +42,14 @@ func newPlugin(c Candidate, cmds []*cobra.Command) (Plugin, error) {
// which would fail here, so there are all real errors.
fullname := filepath.Base(path)
if fullname == "." {
return Plugin{}, errors.Errorf("unable to determine basename of plugin candidate %q", path)
return Plugin{}, fmt.Errorf("unable to determine basename of plugin candidate %q", path)
}
var err error
if fullname, err = trimExeSuffix(fullname); err != nil {
return Plugin{}, errors.Wrapf(err, "plugin candidate %q", path)
return Plugin{}, fmt.Errorf("plugin candidate %q: %w", path, err)
}
if !strings.HasPrefix(fullname, NamePrefix) {
return Plugin{}, errors.Errorf("plugin candidate %q: does not have %q prefix", path, NamePrefix)
return Plugin{}, fmt.Errorf("plugin candidate %q: does not have %q prefix", path, NamePrefix)
}

p := Plugin{
Expand Down
3 changes: 1 addition & 2 deletions cli-plugins/manager/suffix_windows.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package manager

import (
"errors"
"path/filepath"
"strings"

"github.com/pkg/errors"
)

// This is made slightly more complex due to needing to be case insensitive.
Expand Down
3 changes: 1 addition & 2 deletions cli/cobra.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/fvbommel/sortorder"
"github.com/moby/term"
"github.com/morikuni/aec"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -218,7 +217,7 @@ var helpCommand = &cobra.Command{
RunE: func(c *cobra.Command, args []string) error {
cmd, args, e := c.Root().Find(args)
if cmd == nil || e != nil || len(args) > 0 {
return errors.Errorf("unknown help topic: %v", strings.Join(args, " "))
return fmt.Errorf("unknown help topic: %v", strings.Join(args, " "))
}
helpFunc := cmd.HelpFunc()
helpFunc(cmd, args)
Expand Down
2 changes: 1 addition & 1 deletion cli/command/checkpoint/create_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package checkpoint

import (
"errors"
"io"
"strings"
"testing"

"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/checkpoint"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
Expand Down
2 changes: 1 addition & 1 deletion cli/command/checkpoint/list_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package checkpoint

import (
"errors"
"io"
"testing"

"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/checkpoint"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/golden"
Expand Down
2 changes: 1 addition & 1 deletion cli/command/checkpoint/remove_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package checkpoint

import (
"errors"
"io"
"testing"

"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/checkpoint"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
Expand Down
8 changes: 4 additions & 4 deletions cli/command/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package command

import (
"context"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -30,7 +31,6 @@ import (
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/client"
"github.com/docker/go-connections/tlsconfig"
"github.com/pkg/errors"
"github.com/spf13/cobra"
notaryclient "github.com/theupdateframework/notary/client"
)
Expand Down Expand Up @@ -165,7 +165,7 @@ func (cli *DockerCli) BuildKitEnabled() (bool, error) {
if v := os.Getenv("DOCKER_BUILDKIT"); v != "" {
enabled, err := strconv.ParseBool(v)
if err != nil {
return false, errors.Wrap(err, "DOCKER_BUILDKIT environment variable expects boolean value")
return false, fmt.Errorf("DOCKER_BUILDKIT environment variable expects boolean value: %w", err)
}
return enabled, nil
}
Expand Down Expand Up @@ -254,7 +254,7 @@ func NewAPIClientFromFlags(opts *cliflags.ClientOptions, configFile *configfile.
}
endpoint, err := resolveDockerEndpoint(contextStore, resolveContextName(opts, configFile))
if err != nil {
return nil, errors.Wrap(err, "unable to resolve docker endpoint")
return nil, fmt.Errorf("unable to resolve docker endpoint: %w", err)
}
return newAPIClientFromEndpoint(endpoint, configFile)
}
Expand Down Expand Up @@ -436,7 +436,7 @@ func (cli *DockerCli) initialize() error {
cli.init.Do(func() {
cli.dockerEndpoint, cli.initErr = cli.getDockerEndPoint()
if cli.initErr != nil {
cli.initErr = errors.Wrap(cli.initErr, "unable to resolve docker endpoint")
cli.initErr = fmt.Errorf("unable to resolve docker endpoint: %w", cli.initErr)
return
}
if cli.client == nil {
Expand Down
2 changes: 1 addition & 1 deletion cli/command/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package command
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"net"
Expand All @@ -21,7 +22,6 @@ import (
"github.com/docker/docker/api"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
"gotest.tools/v3/fs"
)
Expand Down
3 changes: 1 addition & 2 deletions cli/command/config/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types/swarm"
"github.com/moby/sys/sequential"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -64,7 +63,7 @@ func RunConfigCreate(dockerCli command.Cli, options CreateOptions) error {

configData, err := io.ReadAll(in)
if err != nil {
return errors.Errorf("Error reading content from %q: %v", options.File, err)
return fmt.Errorf("Error reading content from %q: %v", options.File, err)
}

spec := swarm.ConfigSpec{
Expand Down
2 changes: 1 addition & 1 deletion cli/command/config/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"context"
"errors"
"io"
"os"
"path/filepath"
Expand All @@ -12,7 +13,6 @@ import (
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/golden"
Expand Down
2 changes: 1 addition & 1 deletion cli/command/config/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"context"
"errors"
"fmt"
"io"
"testing"
Expand All @@ -10,7 +11,6 @@ import (
"github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/api/types/swarm"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
"gotest.tools/v3/golden"
)
Expand Down
2 changes: 1 addition & 1 deletion cli/command/config/ls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"context"
"errors"
"io"
"testing"
"time"
Expand All @@ -11,7 +12,6 @@ import (
"github.com/docker/cli/internal/test/builders"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/golden"
Expand Down
3 changes: 1 addition & 2 deletions cli/command/config/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -51,7 +50,7 @@ func RunConfigRemove(dockerCli command.Cli, opts RemoveOptions) error {
}

if len(errs) > 0 {
return errors.Errorf("%s", strings.Join(errs, "\n"))
return fmt.Errorf("%s", strings.Join(errs, "\n"))
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion cli/command/config/remove_test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package config

import (
"errors"
"io"
"strings"
"testing"

"github.com/docker/cli/internal/test"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
Expand Down
2 changes: 1 addition & 1 deletion cli/command/container/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package container

import (
"context"
"errors"
"fmt"
"io"

Expand All @@ -12,7 +13,6 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/moby/sys/signal"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down
2 changes: 1 addition & 1 deletion cli/command/container/attach_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package container

import (
"errors"
"fmt"
"io"
"testing"
Expand All @@ -9,7 +10,6 @@ import (
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/pkg/errors"
"gotest.tools/v3/assert"
)

Expand Down
6 changes: 3 additions & 3 deletions cli/command/container/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package container
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"os"
Expand All @@ -20,7 +21,6 @@ import (
"github.com/docker/docker/pkg/system"
units "github.com/docker/go-units"
"github.com/morikuni/aec"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -333,7 +333,7 @@ func copyToContainer(ctx context.Context, dockerCli command.Cli, copyConfig cpCo

// Validate the destination path
if err := command.ValidateOutputPathFileMode(dstStat.Mode); err != nil {
return errors.Wrapf(err, `destination "%s:%s" must be a directory or a regular file`, copyConfig.container, dstPath)
return fmt.Errorf("destination \"%s:%s\" must be a directory or a regular file: %w", copyConfig.container, dstPath, err)
}

// Ignore any error and assume that the parent directory of the destination
Expand All @@ -356,7 +356,7 @@ func copyToContainer(ctx context.Context, dockerCli command.Cli, copyConfig cpCo
content = os.Stdin
resolvedDstPath = dstInfo.Path
if !dstInfo.IsDir {
return errors.Errorf("destination \"%s:%s\" must be a directory", copyConfig.container, dstPath)
return fmt.Errorf("destination \"%s:%s\" must be a directory", copyConfig.container, dstPath)
}
} else {
// Prepare source copy info.
Expand Down
Loading

0 comments on commit 7961d85

Please sign in to comment.