From dbf40e404b467870841ad5e99a31b535c4194d7f Mon Sep 17 00:00:00 2001 From: Sajay Antony Date: Mon, 6 Nov 2023 13:26:09 -0800 Subject: [PATCH] fix: update error message for repo ls (#1169) Signed-off-by: Sajay Antony --- cmd/oras/root/repo/ls.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/oras/root/repo/ls.go b/cmd/oras/root/repo/ls.go index cea8dd334..0d6c3a7c5 100644 --- a/cmd/oras/root/repo/ls.go +++ b/cmd/oras/root/repo/ls.go @@ -17,6 +17,7 @@ package repo import ( "context" + "errors" "fmt" "strings" @@ -74,7 +75,7 @@ func listRepository(ctx context.Context, opts repositoryOptions) error { if err != nil { return err } - return reg.Repositories(ctx, opts.last, func(repos []string) error { + err = reg.Repositories(ctx, opts.last, func(repos []string) error { for _, repo := range repos { if subRepo, found := strings.CutPrefix(repo, opts.namespace); found { fmt.Println(subRepo) @@ -82,4 +83,16 @@ func listRepository(ctx context.Context, opts repositoryOptions) error { } return nil }) + + if err != nil { + var repoErr error + if opts.namespace != "" { + repoErr = fmt.Errorf("could not list repositories for %q with prefix %q", reg.Reference.Host(), opts.namespace) + } else { + repoErr = fmt.Errorf("could not list repositories for %q", reg.Reference.Host()) + } + return errors.Join(repoErr, err) + } + + return nil }