diff --git a/cli/command/manifest/annotate.go b/cli/command/manifest/annotate.go index d832588453e1..6fc898203253 100644 --- a/cli/command/manifest/annotate.go +++ b/cli/command/manifest/annotate.go @@ -5,6 +5,7 @@ import ( "fmt" "path/filepath" + "github.com/containerd/errdefs" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/config" @@ -97,7 +98,7 @@ func runManifestAnnotate(dockerCLI command.Cli, opts annotateOptions) error { manifestStore := newManifestStore(dockerCLI) imageManifest, err := manifestStore.Get(targetRef, imgRef) switch { - case store.IsNotFound(err): + case errdefs.IsNotFound(err): return fmt.Errorf("manifest for image %s does not exist in %s", opts.image, opts.target) case err != nil: return err diff --git a/cli/command/manifest/create_list.go b/cli/command/manifest/create_list.go index 58c18124dfce..71483c0fa80d 100644 --- a/cli/command/manifest/create_list.go +++ b/cli/command/manifest/create_list.go @@ -4,9 +4,9 @@ import ( "context" "fmt" + "github.com/containerd/errdefs" "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" - "github.com/docker/cli/cli/manifest/store" "github.com/pkg/errors" "github.com/spf13/cobra" ) @@ -44,7 +44,7 @@ func createManifestList(ctx context.Context, dockerCLI command.Cli, args []strin manifestStore := newManifestStore(dockerCLI) _, err = manifestStore.GetList(targetRef) switch { - case store.IsNotFound(err): + case errdefs.IsNotFound(err): // New manifest list case err != nil: return err diff --git a/cli/command/manifest/util.go b/cli/command/manifest/util.go index be9fe9ea1ba4..c10a98b0d8f4 100644 --- a/cli/command/manifest/util.go +++ b/cli/command/manifest/util.go @@ -3,9 +3,9 @@ package manifest import ( "context" + "github.com/containerd/errdefs" "github.com/distribution/reference" "github.com/docker/cli/cli/command" - "github.com/docker/cli/cli/manifest/store" "github.com/docker/cli/cli/manifest/types" ) @@ -72,7 +72,7 @@ func normalizeReference(ref string) (reference.Named, error) { func getManifest(ctx context.Context, dockerCLI command.Cli, listRef, namedRef reference.Named, insecure bool) (types.ImageManifest, error) { data, err := newManifestStore(dockerCLI).Get(listRef, namedRef) switch { - case store.IsNotFound(err): + case errdefs.IsNotFound(err): return newRegistryClient(dockerCLI, insecure).GetManifest(ctx, namedRef) case err != nil: return types.ImageManifest{}, err diff --git a/cli/manifest/store/store.go b/cli/manifest/store/store.go index e97e8628f125..7518b5d4a1dc 100644 --- a/cli/manifest/store/store.go +++ b/cli/manifest/store/store.go @@ -6,6 +6,7 @@ import ( "path/filepath" "strings" + "github.com/containerd/errdefs" "github.com/distribution/reference" "github.com/docker/cli/cli/manifest/types" "github.com/docker/distribution/manifest/manifestlist" @@ -152,27 +153,13 @@ func makeFilesafeName(ref string) string { return strings.ReplaceAll(fileName, "/", "_") } -type notFoundError struct { - object string +func newNotFoundError(ref string) error { + return errdefs.ErrNotFound.WithMessage("No such manifest: " + ref) } -func newNotFoundError(ref string) *notFoundError { - return ¬FoundError{object: ref} -} - -func (n *notFoundError) Error() string { - return "No such manifest: " + n.object -} - -// NotFound interface -func (*notFoundError) NotFound() {} - // IsNotFound returns true if the error is a not found error +// +// Deprecated: use [errdefs.IsNotFound]. This function will be removed in the next release. func IsNotFound(err error) bool { - _, ok := err.(notFound) - return ok -} - -type notFound interface { - NotFound() + return errdefs.IsNotFound(err) } diff --git a/cli/manifest/store/store_test.go b/cli/manifest/store/store_test.go index 2b3a57819f8c..d5c3ef67818e 100644 --- a/cli/manifest/store/store_test.go +++ b/cli/manifest/store/store_test.go @@ -4,6 +4,7 @@ import ( "os" "testing" + "github.com/containerd/errdefs" "github.com/distribution/reference" "github.com/docker/cli/cli/manifest/types" "github.com/google/go-cmp/cmp" @@ -86,7 +87,7 @@ func TestStoreSaveAndGet(t *testing.T) { actual, err := store.Get(tc.listRef, tc.manifestRef) if tc.expectedErr != "" { assert.Error(t, err, tc.expectedErr) - assert.Check(t, IsNotFound(err)) + assert.Check(t, errdefs.IsNotFound(err)) return } assert.NilError(t, err) @@ -117,5 +118,5 @@ func TestStoreGetListDoesNotExist(t *testing.T) { listRef := ref("list") _, err := store.GetList(listRef) assert.Error(t, err, "No such manifest: list") - assert.Check(t, IsNotFound(err)) + assert.Check(t, errdefs.IsNotFound(err)) }