- Update IsErrNotFound() to check for the current type before falling back to
detecting the deprecated type.
- Remove unauthorizedError and notImplementedError types, which were not used.
- IsErrPluginPermissionDenied() was added in 7c36a1af031b510cd990cf488ee5998a3efb450f,
but not used at the time, and still appears to be unused.
- Deprecate IsErrUnauthorized in favor of errdefs.IsUnauthorized()
- Deprecate IsErrNotImplemented in favor of errdefs,IsNotImplemented()
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -40,11 +40,11 @@ type notFound interface {
|
| 40 | 40 |
// IsErrNotFound returns true if the error is a NotFound error, which is returned |
| 41 | 41 |
// by the API when some object is not found. |
| 42 | 42 |
func IsErrNotFound(err error) bool {
|
| 43 |
- var e notFound |
|
| 44 |
- if errors.As(err, &e) {
|
|
| 43 |
+ if errdefs.IsNotFound(err) {
|
|
| 45 | 44 |
return true |
| 46 | 45 |
} |
| 47 |
- return errdefs.IsNotFound(err) |
|
| 46 |
+ var e notFound |
|
| 47 |
+ return errors.As(err, &e) |
|
| 48 | 48 |
} |
| 49 | 49 |
|
| 50 | 50 |
type objectNotFoundError struct {
|
| ... | ... |
@@ -58,22 +58,11 @@ func (e objectNotFoundError) Error() string {
|
| 58 | 58 |
return fmt.Sprintf("Error: No such %s: %s", e.object, e.id)
|
| 59 | 59 |
} |
| 60 | 60 |
|
| 61 |
-// unauthorizedError represents an authorization error in a remote registry. |
|
| 62 |
-type unauthorizedError struct {
|
|
| 63 |
- cause error |
|
| 64 |
-} |
|
| 65 |
- |
|
| 66 |
-// Error returns a string representation of an unauthorizedError |
|
| 67 |
-func (u unauthorizedError) Error() string {
|
|
| 68 |
- return u.cause.Error() |
|
| 69 |
-} |
|
| 70 |
- |
|
| 71 | 61 |
// IsErrUnauthorized returns true if the error is caused |
| 72 | 62 |
// when a remote registry authentication fails |
| 63 |
+// |
|
| 64 |
+// Deprecated: use errdefs.IsUnauthorized |
|
| 73 | 65 |
func IsErrUnauthorized(err error) bool {
|
| 74 |
- if _, ok := err.(unauthorizedError); ok {
|
|
| 75 |
- return ok |
|
| 76 |
- } |
|
| 77 | 66 |
return errdefs.IsUnauthorized(err) |
| 78 | 67 |
} |
| 79 | 68 |
|
| ... | ... |
@@ -85,32 +74,12 @@ func (e pluginPermissionDenied) Error() string {
|
| 85 | 85 |
return "Permission denied while installing plugin " + e.name |
| 86 | 86 |
} |
| 87 | 87 |
|
| 88 |
-// IsErrPluginPermissionDenied returns true if the error is caused |
|
| 89 |
-// when a user denies a plugin's permissions |
|
| 90 |
-func IsErrPluginPermissionDenied(err error) bool {
|
|
| 91 |
- _, ok := err.(pluginPermissionDenied) |
|
| 92 |
- return ok |
|
| 93 |
-} |
|
| 94 |
- |
|
| 95 |
-type notImplementedError struct {
|
|
| 96 |
- message string |
|
| 97 |
-} |
|
| 98 |
- |
|
| 99 |
-func (e notImplementedError) Error() string {
|
|
| 100 |
- return e.message |
|
| 101 |
-} |
|
| 102 |
- |
|
| 103 |
-func (e notImplementedError) NotImplemented() bool {
|
|
| 104 |
- return true |
|
| 105 |
-} |
|
| 106 |
- |
|
| 107 | 88 |
// IsErrNotImplemented returns true if the error is a NotImplemented error. |
| 108 | 89 |
// This is returned by the API when a requested feature has not been |
| 109 | 90 |
// implemented. |
| 91 |
+// |
|
| 92 |
+// Deprecated: use errdefs.IsNotImplemented |
|
| 110 | 93 |
func IsErrNotImplemented(err error) bool {
|
| 111 |
- if _, ok := err.(notImplementedError); ok {
|
|
| 112 |
- return ok |
|
| 113 |
- } |
|
| 114 | 94 |
return errdefs.IsNotImplemented(err) |
| 115 | 95 |
} |
| 116 | 96 |
|
| ... | ... |
@@ -9,6 +9,7 @@ import ( |
| 9 | 9 |
"github.com/docker/docker/api/types" |
| 10 | 10 |
"github.com/docker/docker/api/types/filters" |
| 11 | 11 |
"github.com/docker/docker/client" |
| 12 |
+ "github.com/docker/docker/errdefs" |
|
| 12 | 13 |
"gotest.tools/v3/assert" |
| 13 | 14 |
) |
| 14 | 15 |
|
| ... | ... |
@@ -164,7 +165,7 @@ func deleteAllPlugins(t testing.TB, c client.PluginAPIClient, protectedPlugins m |
| 164 | 164 |
t.Helper() |
| 165 | 165 |
plugins, err := c.PluginList(context.Background(), filters.Args{})
|
| 166 | 166 |
// Docker EE does not allow cluster-wide plugin management. |
| 167 |
- if client.IsErrNotImplemented(err) {
|
|
| 167 |
+ if errdefs.IsNotImplemented(err) {
|
|
| 168 | 168 |
return |
| 169 | 169 |
} |
| 170 | 170 |
assert.Check(t, err, "failed to list plugins") |
| ... | ... |
@@ -6,7 +6,7 @@ import ( |
| 6 | 6 |
|
| 7 | 7 |
"github.com/docker/docker/api/types" |
| 8 | 8 |
"github.com/docker/docker/api/types/filters" |
| 9 |
- dclient "github.com/docker/docker/client" |
|
| 9 |
+ "github.com/docker/docker/errdefs" |
|
| 10 | 10 |
"gotest.tools/v3/assert" |
| 11 | 11 |
) |
| 12 | 12 |
|
| ... | ... |
@@ -180,7 +180,7 @@ func getExistingPlugins(t testing.TB, testEnv *Execution) []string {
|
| 180 | 180 |
client := testEnv.APIClient() |
| 181 | 181 |
pluginList, err := client.PluginList(context.Background(), filters.Args{})
|
| 182 | 182 |
// Docker EE does not allow cluster-wide plugin management. |
| 183 |
- if dclient.IsErrNotImplemented(err) {
|
|
| 183 |
+ if errdefs.IsNotImplemented(err) {
|
|
| 184 | 184 |
return []string{}
|
| 185 | 185 |
} |
| 186 | 186 |
assert.NilError(t, err, "failed to list plugins") |