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 }