fix(sdk): Polish the downloader/manager package error return

Close #8471

Signed-off-by: Dong Gang <dong.gang@daocloud.io>
pull/8491/head
Dong Gang 5 years ago
parent 241785c70f
commit 3e275baef7

@ -19,7 +19,9 @@ import (
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"github.com/pkg/errors"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"k8s.io/client-go/util/homedir" "k8s.io/client-go/util/homedir"
@ -65,7 +67,11 @@ func newDependencyBuildCmd(out io.Writer) *cobra.Command {
if client.Verify { if client.Verify {
man.Verify = downloader.VerifyIfPossible 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
}, },
} }

@ -42,6 +42,16 @@ import (
"helm.sh/helm/v3/pkg/repo" "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. // Manager handles the lifecycle of fetching, resolving, and storing dependencies.
type Manager struct { type Manager struct {
// Out is used to print warnings and notifications. // Out is used to print warnings and notifications.
@ -411,7 +421,7 @@ Loop:
missing = append(missing, dd.Repository) missing = append(missing, dd.Repository)
} }
if len(missing) > 0 { 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 return nil
} }

Loading…
Cancel
Save