Skip to content

Commit 7146021

Browse files
committed
cli-plugins/manager: deprecate "IsNotFound"
These errors satisfy errdefs.IsNotFound, so make it a wrapper, and deprecate it. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 1cc698c commit 7146021

4 files changed

Lines changed: 17 additions & 18 deletions

File tree

cli-plugins/manager/manager.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
"sync"
1111

12+
"github.com/containerd/errdefs"
1213
"github.com/docker/cli/cli-plugins/metadata"
1314
"github.com/docker/cli/cli/config"
1415
"github.com/docker/cli/cli/config/configfile"
@@ -40,15 +41,11 @@ func (e errPluginNotFound) Error() string {
4041
return "Error: No such CLI plugin: " + string(e)
4142
}
4243

43-
type notFound interface{ NotFound() }
44-
4544
// IsNotFound is true if the given error is due to a plugin not being found.
45+
//
46+
// Deprecated: use [errdefs.IsNotFound].
4647
func IsNotFound(err error) bool {
47-
if e, ok := err.(*pluginError); ok {
48-
err = e.Cause()
49-
}
50-
_, ok := err.(notFound)
51-
return ok
48+
return errdefs.IsNotFound(err)
5249
}
5350

5451
// getPluginDirs returns the platform-specific locations to search for plugins
@@ -127,7 +124,7 @@ func getPlugin(name string, pluginDirs []string, rootcmd *cobra.Command) (*Plugi
127124
if err != nil {
128125
return nil, err
129126
}
130-
if !IsNotFound(p.Err) {
127+
if !errdefs.IsNotFound(p.Err) {
131128
p.ShadowedPaths = paths[1:]
132129
}
133130
return &p, nil
@@ -164,7 +161,7 @@ func ListPlugins(dockerCli config.Provider, rootcmd *cobra.Command) ([]Plugin, e
164161
if err != nil {
165162
return err
166163
}
167-
if !IsNotFound(p.Err) {
164+
if !errdefs.IsNotFound(p.Err) {
168165
p.ShadowedPaths = paths[1:]
169166
mu.Lock()
170167
defer mu.Unlock()
@@ -185,9 +182,9 @@ func ListPlugins(dockerCli config.Provider, rootcmd *cobra.Command) ([]Plugin, e
185182
return plugins, nil
186183
}
187184

188-
// PluginRunCommand returns an "os/exec".Cmd which when .Run() will execute the named plugin.
185+
// PluginRunCommand returns an [os/exec.Cmd] which when [os/exec.Cmd.Run] will execute the named plugin.
189186
// The rootcmd argument is referenced to determine the set of builtin commands in order to detect conficts.
190-
// The error returned satisfies the IsNotFound() predicate if no plugin was found or if the first candidate plugin was invalid somehow.
187+
// The error returned satisfies the [errdefs.IsNotFound] predicate if no plugin was found or if the first candidate plugin was invalid somehow.
191188
func PluginRunCommand(dockerCli config.Provider, name string, rootcmd *cobra.Command) (*exec.Cmd, error) {
192189
// This uses the full original args, not the args which may
193190
// have been provided by cobra to our caller. This is because

cli-plugins/manager/manager_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66
"testing"
77

8+
"github.com/containerd/errdefs"
89
"github.com/docker/cli/cli/config"
910
"github.com/docker/cli/cli/config/configfile"
1011
"github.com/docker/cli/internal/test"
@@ -131,7 +132,7 @@ echo '{"SchemaVersion":"0.1.0"}'`, fs.WithMode(0o777)),
131132

132133
_, err = GetPlugin("ccc", cli, &cobra.Command{})
133134
assert.Error(t, err, "Error: No such CLI plugin: ccc")
134-
assert.Assert(t, IsNotFound(err))
135+
assert.Assert(t, errdefs.IsNotFound(err))
135136
}
136137

137138
func TestListPluginsIsSorted(t *testing.T) {
@@ -166,8 +167,8 @@ func TestErrPluginNotFound(t *testing.T) {
166167
var err error = errPluginNotFound("test")
167168
err.(errPluginNotFound).NotFound()
168169
assert.Error(t, err, "Error: No such CLI plugin: test")
169-
assert.Assert(t, IsNotFound(err))
170-
assert.Assert(t, !IsNotFound(nil))
170+
assert.Assert(t, errdefs.IsNotFound(err))
171+
assert.Assert(t, !errdefs.IsNotFound(nil))
171172
}
172173

173174
func TestGetPluginDirs(t *testing.T) {

cmd/docker/builder.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strconv"
99
"strings"
1010

11+
"github.com/containerd/errdefs"
1112
pluginmanager "github.com/docker/cli/cli-plugins/manager"
1213
"github.com/docker/cli/cli-plugins/metadata"
1314
"github.com/docker/cli/cli/command"
@@ -36,7 +37,7 @@ const (
3637
)
3738

3839
func newBuilderError(errorMsg string, pluginLoadErr error) error {
39-
if pluginmanager.IsNotFound(pluginLoadErr) {
40+
if errdefs.IsNotFound(pluginLoadErr) {
4041
return errors.New(errorMsg)
4142
}
4243
if pluginLoadErr != nil {

cmd/docker/docker.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func setupHelpCommand(dockerCli command.Cli, rootCmd, helpCmd *cobra.Command) {
201201
if err == nil {
202202
return helpcmd.Run()
203203
}
204-
if !pluginmanager.IsNotFound(err) {
204+
if !errdefs.IsNotFound(err) {
205205
return fmt.Errorf("unknown help topic: %v", strings.Join(args, " "))
206206
}
207207
}
@@ -240,7 +240,7 @@ func setHelpFunc(dockerCli command.Cli, cmd *cobra.Command) {
240240
if err == nil {
241241
return
242242
}
243-
if !pluginmanager.IsNotFound(err) {
243+
if !errdefs.IsNotFound(err) {
244244
ccmd.Println(err)
245245
return
246246
}
@@ -473,7 +473,7 @@ func runDocker(ctx context.Context, dockerCli *command.DockerCli) error {
473473
}
474474
return nil
475475
}
476-
if !pluginmanager.IsNotFound(err) {
476+
if !errdefs.IsNotFound(err) {
477477
// For plugin not found we fall through to
478478
// cmd.Execute() which deals with reporting
479479
// "command not found" in a consistent way.

0 commit comments

Comments
 (0)