Skip to content

Commit 29c1aba

Browse files
authored
Merge pull request #5903 from thaJeztah/cli_plugins_no_pkg_errors
cli-plugins/manager: use stdlib errors, and minor cleanup
2 parents 571124d + 8fc0c74 commit 29c1aba

3 files changed

Lines changed: 13 additions & 18 deletions

File tree

cli-plugins/manager/error.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
package manager
55

66
import (
7-
"github.com/pkg/errors"
7+
"fmt"
88
)
99

1010
// pluginError is set as Plugin.Err by NewPlugin if the plugin
@@ -39,16 +39,16 @@ func (e *pluginError) MarshalText() (text []byte, err error) {
3939
}
4040

4141
// wrapAsPluginError wraps an error in a pluginError with an
42-
// additional message, analogous to errors.Wrapf.
42+
// additional message.
4343
func wrapAsPluginError(err error, msg string) error {
4444
if err == nil {
4545
return nil
4646
}
47-
return &pluginError{cause: errors.Wrap(err, msg)}
47+
return &pluginError{cause: fmt.Errorf("%s: %w", msg, err)}
4848
}
4949

5050
// NewPluginError creates a new pluginError, analogous to
5151
// errors.Errorf.
5252
func NewPluginError(msg string, args ...any) error {
53-
return &pluginError{cause: errors.Errorf(msg, args...)}
53+
return &pluginError{cause: fmt.Errorf(msg, args...)}
5454
}

cli-plugins/manager/plugin.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ package manager
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
7+
"fmt"
68
"os"
79
"os/exec"
810
"path/filepath"
911
"regexp"
1012
"strings"
1113

1214
"github.com/docker/cli/cli-plugins/metadata"
13-
"github.com/pkg/errors"
1415
"github.com/spf13/cobra"
1516
)
1617

@@ -45,14 +46,14 @@ func newPlugin(c Candidate, cmds []*cobra.Command) (Plugin, error) {
4546
// which would fail here, so there are all real errors.
4647
fullname := filepath.Base(path)
4748
if fullname == "." {
48-
return Plugin{}, errors.Errorf("unable to determine basename of plugin candidate %q", path)
49+
return Plugin{}, fmt.Errorf("unable to determine basename of plugin candidate %q", path)
4950
}
5051
var err error
5152
if fullname, err = trimExeSuffix(fullname); err != nil {
52-
return Plugin{}, errors.Wrapf(err, "plugin candidate %q", path)
53+
return Plugin{}, fmt.Errorf("plugin candidate %q: %w", path, err)
5354
}
5455
if !strings.HasPrefix(fullname, metadata.NamePrefix) {
55-
return Plugin{}, errors.Errorf("plugin candidate %q: does not have %q prefix", path, metadata.NamePrefix)
56+
return Plugin{}, fmt.Errorf("plugin candidate %q: does not have %q prefix", path, metadata.NamePrefix)
5657
}
5758

5859
p := Plugin{

cli-plugins/manager/suffix_windows.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
package manager
22

33
import (
4+
"fmt"
45
"path/filepath"
56
"strings"
6-
7-
"github.com/pkg/errors"
87
)
98

10-
// This is made slightly more complex due to needing to be case insensitive.
9+
// This is made slightly more complex due to needing to be case-insensitive.
1110
func trimExeSuffix(s string) (string, error) {
1211
ext := filepath.Ext(s)
13-
if ext == "" {
14-
return "", errors.Errorf("path %q lacks required file extension", s)
15-
}
16-
17-
exe := ".exe"
18-
if !strings.EqualFold(ext, exe) {
19-
return "", errors.Errorf("path %q lacks required %q suffix", s, exe)
12+
if ext == "" || !strings.EqualFold(ext, ".exe") {
13+
return "", fmt.Errorf("path %q lacks required file extension (.exe)", s)
2014
}
2115
return strings.TrimSuffix(s, ext), nil
2216
}

0 commit comments

Comments
 (0)