From 3e275baef7c96728a2ec7df27f5bbcae89a1c0bb Mon Sep 17 00:00:00 2001 From: Dong Gang Date: Tue, 21 Jul 2020 10:11:19 +0800 Subject: [PATCH] fix(sdk): Polish the downloader/manager package error return Close #8471 Signed-off-by: Dong Gang --- cmd/helm/dependency_build.go | 8 +++++++- pkg/downloader/manager.go | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/cmd/helm/dependency_build.go b/cmd/helm/dependency_build.go index 478b49479..a610fb911 100644 --- a/cmd/helm/dependency_build.go +++ b/cmd/helm/dependency_build.go @@ -19,7 +19,9 @@ import ( "io" "os" "path/filepath" + "strings" + "github.com/pkg/errors" "github.com/spf13/cobra" "k8s.io/client-go/util/homedir" @@ -65,7 +67,11 @@ func newDependencyBuildCmd(out io.Writer) *cobra.Command { if client.Verify { man.Verify = downloader.VerifyIfPossible } - return man.Build() + err := man.Build() + if e, ok := err.(downloader.ErrRepoNotFound); ok { + return errors.Errorf("no repository definition for %s. Please add the missing repos via 'helm repo add'", strings.Join(e.Repos, ", ")) + } + return err }, } diff --git a/pkg/downloader/manager.go b/pkg/downloader/manager.go index 00198de0c..1479cc9a6 100644 --- a/pkg/downloader/manager.go +++ b/pkg/downloader/manager.go @@ -42,6 +42,16 @@ import ( "helm.sh/helm/v3/pkg/repo" ) +// ErrRepoNotFound indicates that chart repositories can't be found in local repo cache. +// The value of Repos is missing repos. +type ErrRepoNotFound struct { + Repos []string +} + +func (e ErrRepoNotFound) Error() string { + return fmt.Sprintf("no repository definition for %s", strings.Join(e.Repos, ", ")) +} + // Manager handles the lifecycle of fetching, resolving, and storing dependencies. type Manager struct { // Out is used to print warnings and notifications. @@ -411,7 +421,7 @@ Loop: missing = append(missing, dd.Repository) } if len(missing) > 0 { - return errors.Errorf("no repository definition for %s. Please add the missing repos via 'helm repo add'", strings.Join(missing, ", ")) + return ErrRepoNotFound{missing} } return nil }