Skip to content

Commit

Permalink
chore: improve error message if the provided annotation file is inval…
Browse files Browse the repository at this point in the history
…id (#1255)

Signed-off-by: Xiaoxuan Wang <[email protected]>
  • Loading branch information
wangxiaoxuan273 authored Jan 29, 2024
1 parent 33dd0b0 commit 06097c0
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions cmd/oras/internal/option/packer.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,10 @@ func (opts *Packer) LoadManifestAnnotations() (annotations map[string]map[string
}
if opts.AnnotationFilePath != "" {
if err = decodeJSON(opts.AnnotationFilePath, &annotations); err != nil {
errStr := err.Error()
docLink := " Please refer to the document at https://oras.land/docs/how_to_guides/manifest_annotations."
if !strings.HasSuffix(errStr, ".") {
docLink = "." + docLink
return nil, &oerrors.Error{
Err: fmt.Errorf(`invalid annotation json file: failed to load annotations from %s`, opts.AnnotationFilePath),
Recommendation: `Annotation file doesn't match the required format. Please refer to the document at https://oras.land/docs/how_to_guides/manifest_annotations`,
}
return nil, fmt.Errorf("failed to load annotations from %s: %w"+
docLink, opts.AnnotationFilePath, err)
}
}
if len(opts.ManifestAnnotations) != 0 {
Expand Down

0 comments on commit 06097c0

Please sign in to comment.