Skip to content

Commit

Permalink
chore: make error returned by oras tag more readable (#1058)
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <jinzha1@microsoft.com>
  • Loading branch information
qweeah authored Aug 9, 2023
1 parent dcc112b commit ceb56f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions cmd/oras/root/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/spf13/cobra"
"oras.land/oras-go/v2"
"oras.land/oras-go/v2/registry"
"oras.land/oras/cmd/oras/internal/display"
"oras.land/oras/cmd/oras/internal/option"
)
Expand Down Expand Up @@ -58,6 +59,9 @@ Example - Tag the manifest 'v1.0.1' to 'v1.0.2' in an OCI image layout folder 'l
Args: cobra.MinimumNArgs(2),
PreRunE: func(cmd *cobra.Command, args []string) error {
opts.RawReference = args[0]
if _, err := registry.ParseReference(opts.RawReference); err != nil {
return fmt.Errorf("unable to add tag for '%s': %w", opts.RawReference, err)
}
opts.targetRefs = args[1:]
return option.Parse(&opts)
},
Expand Down
6 changes: 5 additions & 1 deletion test/e2e/suite/command/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ var _ = Describe("ORAS beginners:", func() {
})

It("should fail when provided manifest reference is not found", func() {
ORAS("tag", RegistryRef(Host, ImageRepo, "i-dont-think-this-tag-exists")).ExpectFailure().MatchErrKeyWords("Error:").Exec()
ORAS("tag", RegistryRef(Host, ImageRepo, "i-dont-think-this-tag-exists"), "tagged").ExpectFailure().MatchErrKeyWords("Error:").Exec()
})

It("should fail when provided invalid reference", func() {
ORAS("tag", "list", "tagged").ExpectFailure().MatchErrKeyWords("Error:", "'list'").Exec()
})
})
})
Expand Down

0 comments on commit ceb56f8

Please sign in to comment.