Skip to content

Commit 5a4758f

Browse files
Merge pull request #6513 from thaJeztah/manifeststore_notfound
cli/manifest/store: deprecate IsNotFound
2 parents 1b467f9 + f3fb772 commit 5a4758f

File tree

5 files changed

+15
-26
lines changed

5 files changed

+15
-26
lines changed

cli/command/manifest/annotate.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"path/filepath"
77

8+
"github.com/containerd/errdefs"
89
"github.com/docker/cli/cli"
910
"github.com/docker/cli/cli/command"
1011
"github.com/docker/cli/cli/config"
@@ -97,7 +98,7 @@ func runManifestAnnotate(dockerCLI command.Cli, opts annotateOptions) error {
9798
manifestStore := newManifestStore(dockerCLI)
9899
imageManifest, err := manifestStore.Get(targetRef, imgRef)
99100
switch {
100-
case store.IsNotFound(err):
101+
case errdefs.IsNotFound(err):
101102
return fmt.Errorf("manifest for image %s does not exist in %s", opts.image, opts.target)
102103
case err != nil:
103104
return err

cli/command/manifest/create_list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"errors"
66
"fmt"
77

8+
"github.com/containerd/errdefs"
89
"github.com/docker/cli/cli"
910
"github.com/docker/cli/cli/command"
10-
"github.com/docker/cli/cli/manifest/store"
1111
"github.com/spf13/cobra"
1212
)
1313

@@ -45,7 +45,7 @@ func createManifestList(ctx context.Context, dockerCLI command.Cli, args []strin
4545
manifestStore := newManifestStore(dockerCLI)
4646
_, err = manifestStore.GetList(targetRef)
4747
switch {
48-
case store.IsNotFound(err):
48+
case errdefs.IsNotFound(err):
4949
// New manifest list
5050
case err != nil:
5151
return err

cli/command/manifest/util.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package manifest
33
import (
44
"context"
55

6+
"github.com/containerd/errdefs"
67
"github.com/distribution/reference"
78
"github.com/docker/cli/cli/command"
8-
"github.com/docker/cli/cli/manifest/store"
99
"github.com/docker/cli/cli/manifest/types"
1010
)
1111

@@ -72,7 +72,7 @@ func normalizeReference(ref string) (reference.Named, error) {
7272
func getManifest(ctx context.Context, dockerCLI command.Cli, listRef, namedRef reference.Named, insecure bool) (types.ImageManifest, error) {
7373
data, err := newManifestStore(dockerCLI).Get(listRef, namedRef)
7474
switch {
75-
case store.IsNotFound(err):
75+
case errdefs.IsNotFound(err):
7676
return newRegistryClient(dockerCLI, insecure).GetManifest(ctx, namedRef)
7777
case err != nil:
7878
return types.ImageManifest{}, err

cli/manifest/store/store.go

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"path/filepath"
88
"strings"
99

10+
"github.com/containerd/errdefs"
1011
"github.com/distribution/reference"
1112
"github.com/docker/cli/cli/manifest/types"
1213
"github.com/docker/distribution/manifest/manifestlist"
@@ -152,27 +153,13 @@ func makeFilesafeName(ref string) string {
152153
return strings.ReplaceAll(fileName, "/", "_")
153154
}
154155

155-
type notFoundError struct {
156-
object string
156+
func newNotFoundError(ref string) error {
157+
return errdefs.ErrNotFound.WithMessage("No such manifest: " + ref)
157158
}
158159

159-
func newNotFoundError(ref string) *notFoundError {
160-
return &notFoundError{object: ref}
161-
}
162-
163-
func (n *notFoundError) Error() string {
164-
return "No such manifest: " + n.object
165-
}
166-
167-
// NotFound interface
168-
func (*notFoundError) NotFound() {}
169-
170160
// IsNotFound returns true if the error is a not found error
161+
//
162+
// Deprecated: use [errdefs.IsNotFound]. This function will be removed in the next release.
171163
func IsNotFound(err error) bool {
172-
_, ok := err.(notFound)
173-
return ok
174-
}
175-
176-
type notFound interface {
177-
NotFound()
164+
return errdefs.IsNotFound(err)
178165
}

cli/manifest/store/store_test.go

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

7+
"github.com/containerd/errdefs"
78
"github.com/distribution/reference"
89
"github.com/docker/cli/cli/manifest/types"
910
"github.com/google/go-cmp/cmp"
@@ -86,7 +87,7 @@ func TestStoreSaveAndGet(t *testing.T) {
8687
actual, err := store.Get(tc.listRef, tc.manifestRef)
8788
if tc.expectedErr != "" {
8889
assert.Error(t, err, tc.expectedErr)
89-
assert.Check(t, IsNotFound(err))
90+
assert.Check(t, errdefs.IsNotFound(err))
9091
return
9192
}
9293
assert.NilError(t, err)
@@ -117,5 +118,5 @@ func TestStoreGetListDoesNotExist(t *testing.T) {
117118
listRef := ref("list")
118119
_, err := store.GetList(listRef)
119120
assert.Error(t, err, "No such manifest: list")
120-
assert.Check(t, IsNotFound(err))
121+
assert.Check(t, errdefs.IsNotFound(err))
121122
}

0 commit comments

Comments
 (0)