From 06097c068e6b34e0d5ffed5bc9f11621959acefe Mon Sep 17 00:00:00 2001 From: Xiaoxuan Wang <103478229+wangxiaoxuan273@users.noreply.github.com> Date: Mon, 29 Jan 2024 12:20:01 +0800 Subject: [PATCH] chore: improve error message if the provided annotation file is invalid (#1255) Signed-off-by: Xiaoxuan Wang --- cmd/oras/internal/option/packer.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/cmd/oras/internal/option/packer.go b/cmd/oras/internal/option/packer.go index 514c7ce60..7b74a881e 100644 --- a/cmd/oras/internal/option/packer.go +++ b/cmd/oras/internal/option/packer.go @@ -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 {