diff --git a/cmd/oras/internal/errors/errors.go b/cmd/oras/internal/errors/errors.go index e3c6e4c43..2c3fd8bf5 100644 --- a/cmd/oras/internal/errors/errors.go +++ b/cmd/oras/internal/errors/errors.go @@ -21,12 +21,12 @@ import ( "oras.land/oras-go/v2/registry" ) -// NewErrInvalidReference creates a new error based on the reference string. -func NewErrInvalidReference(ref registry.Reference) error { - return NewErrInvalidReferenceStr(ref.String()) +// NewErrEmptyTagOrDigest creates a new error based on the reference string. +func NewErrEmptyTagOrDigest(ref registry.Reference) error { + return NewErrEmptyTagOrDigestStr(ref.String()) } -// NewErrInvalidReferenceStr creates a new error based on the reference string. -func NewErrInvalidReferenceStr(ref string) error { - return fmt.Errorf("%s: invalid image reference, expecting ", ref) +// NewErrEmptyTagOrDigestStr creates a new error based on the reference string. +func NewErrEmptyTagOrDigestStr(ref string) error { + return fmt.Errorf("%q: no tag or digest when expecting ", ref) } diff --git a/cmd/oras/internal/option/remote.go b/cmd/oras/internal/option/remote.go index bf014c74b..26c01fc90 100644 --- a/cmd/oras/internal/option/remote.go +++ b/cmd/oras/internal/option/remote.go @@ -18,6 +18,7 @@ package option import ( "context" "crypto/tls" + "errors" "fmt" "io" "net" @@ -30,6 +31,7 @@ import ( credentials "github.com/oras-project/oras-credentials-go" "github.com/sirupsen/logrus" "github.com/spf13/pflag" + "oras.land/oras-go/v2/errdef" "oras.land/oras-go/v2/registry/remote" "oras.land/oras-go/v2/registry/remote/auth" "oras.land/oras-go/v2/registry/remote/retry" @@ -290,6 +292,9 @@ func (opts *Remote) NewRegistry(registry string, common Common, logger logrus.Fi func (opts *Remote) NewRepository(reference string, common Common, logger logrus.FieldLogger) (repo *remote.Repository, err error) { repo, err = remote.NewRepository(reference) if err != nil { + if errors.Unwrap(err) == errdef.ErrInvalidReference { + return nil, fmt.Errorf("%q: %v", reference, err) + } return nil, err } registry := repo.Reference.Registry diff --git a/cmd/oras/internal/option/target.go b/cmd/oras/internal/option/target.go index 36290204e..849a739e1 100644 --- a/cmd/oras/internal/option/target.go +++ b/cmd/oras/internal/option/target.go @@ -177,7 +177,7 @@ func (opts *Target) NewReadonlyTarget(ctx context.Context, common Common, logger // EnsureReferenceNotEmpty ensures whether the tag or digest is empty. func (opts *Target) EnsureReferenceNotEmpty() error { if opts.Reference == "" { - return oerrors.NewErrInvalidReferenceStr(opts.RawReference) + return oerrors.NewErrEmptyTagOrDigestStr(opts.RawReference) } return nil } diff --git a/cmd/oras/root/manifest/delete.go b/cmd/oras/root/manifest/delete.go index 06b449f20..467ef04f4 100644 --- a/cmd/oras/root/manifest/delete.go +++ b/cmd/oras/root/manifest/delete.go @@ -85,7 +85,7 @@ func deleteManifest(ctx context.Context, opts deleteOptions) error { } if repo.Reference.Reference == "" { - return oerrors.NewErrInvalidReference(repo.Reference) + return oerrors.NewErrEmptyTagOrDigest(repo.Reference) } // add both pull and delete scope hints for dst repository to save potential delete-scope token requests during deleting diff --git a/test/e2e/suite/command/discover.go b/test/e2e/suite/command/discover.go index d746cdca7..42c59da07 100644 --- a/test/e2e/suite/command/discover.go +++ b/test/e2e/suite/command/discover.go @@ -61,7 +61,7 @@ var _ = Describe("ORAS beginners:", func() { }) It("should fail when no tag or digest found in provided subject reference", func() { - ORAS("discover", RegistryRef(ZOTHost, ImageRepo, "")).ExpectFailure().MatchErrKeyWords("Error:", "invalid image reference").Exec() + ORAS("discover", RegistryRef(ZOTHost, ImageRepo, "")).ExpectFailure().MatchErrKeyWords("Error:", "no tag or digest").Exec() }) }) }) diff --git a/test/e2e/suite/command/manifest.go b/test/e2e/suite/command/manifest.go index 475301712..bf8950c92 100644 --- a/test/e2e/suite/command/manifest.go +++ b/test/e2e/suite/command/manifest.go @@ -268,7 +268,7 @@ var _ = Describe("1.1 registry users:", func() { }) It("should fail if no manifest tag or digest is provided", func() { - ORAS("manifest", "fetch", RegistryRef(ZOTHost, ImageRepo, "")).ExpectFailure().MatchErrKeyWords("Error:", "invalid image reference").Exec() + ORAS("manifest", "fetch", RegistryRef(ZOTHost, ImageRepo, "")).ExpectFailure().MatchErrKeyWords("Error:", "no tag or digest").Exec() }) }) @@ -331,7 +331,7 @@ var _ = Describe("1.1 registry users:", func() { MatchContent(multi_arch.LinuxAMD64ConfigDesc).Exec() }) It("should fail if no manifest tag or digest is provided", func() { - ORAS("manifest", "fetch-config", RegistryRef(ZOTHost, ImageRepo, "")).ExpectFailure().MatchErrKeyWords("Error:", "invalid image reference").Exec() + ORAS("manifest", "fetch-config", RegistryRef(ZOTHost, ImageRepo, "")).ExpectFailure().MatchErrKeyWords("Error:", "no tag or digest").Exec() }) }) @@ -446,7 +446,7 @@ var _ = Describe("OCI image layout users:", func() { It("should fail if no manifest tag or digest is provided", func() { root := PrepareTempOCI(ImageRepo) ORAS("manifest", "fetch", Flags.Layout, root).ExpectFailure(). - MatchErrKeyWords("Error:", "invalid image reference").Exec() + MatchErrKeyWords("Error:", "no tag or digest").Exec() }) }) @@ -491,7 +491,7 @@ var _ = Describe("OCI image layout users:", func() { }) It("should fail if no manifest tag or digest is provided", func() { root := prepare(foobar.Tag) - ORAS("manifest", "fetch-config", Flags.Layout, root).ExpectFailure().MatchErrKeyWords("Error:", "invalid image reference").Exec() + ORAS("manifest", "fetch-config", Flags.Layout, root).ExpectFailure().MatchErrKeyWords("Error:", "no tag or digest").Exec() }) }) })