Merge pull request #31408 from AndiDog/plugin-err-msg

Improve error message when plugin source cannot be determined or a non-directory is passed
pull/31412/head
Matt Farina 11 months ago committed by GitHub
commit a3db5f5667
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -139,18 +139,24 @@ func Update(i Installer) error {
} }
// NewForSource determines the correct Installer for the given source. // NewForSource determines the correct Installer for the given source.
func NewForSource(source, version string) (Installer, error) { func NewForSource(source, version string) (installer Installer, err error) {
// Check if source is an OCI registry reference
if strings.HasPrefix(source, fmt.Sprintf("%s://", registry.OCIScheme)) { if strings.HasPrefix(source, fmt.Sprintf("%s://", registry.OCIScheme)) {
return NewOCIInstaller(source) // Source is an OCI registry reference
} installer, err = NewOCIInstaller(source)
// Check if source is a local directory } else if isLocalReference(source) {
if isLocalReference(source) { // Source is a local directory
return NewLocalInstaller(source) installer, err = NewLocalInstaller(source)
} else if isRemoteHTTPArchive(source) { } else if isRemoteHTTPArchive(source) {
return NewHTTPInstaller(source) installer, err = NewHTTPInstaller(source)
} else {
installer, err = NewVCSInstaller(source, version)
}
if err != nil {
return installer, fmt.Errorf("cannot get information about plugin source %q (if it's a local directory, does it exist?), last error was: %w", source, err)
} }
return NewVCSInstaller(source, version)
return
} }
// FindSource determines the correct Installer for the given source. // FindSource determines the correct Installer for the given source.

@ -29,8 +29,8 @@ import (
"helm.sh/helm/v4/pkg/helmpath" "helm.sh/helm/v4/pkg/helmpath"
) )
// ErrPluginNotAFolder indicates that the plugin path is not a folder. // ErrPluginNotADirectory indicates that the plugin path is not a directory.
var ErrPluginNotAFolder = errors.New("expected plugin to be a folder") var ErrPluginNotADirectory = errors.New("expected plugin to be a directory (containing a file 'plugin.yaml')")
// LocalInstaller installs plugins from the filesystem. // LocalInstaller installs plugins from the filesystem.
type LocalInstaller struct { type LocalInstaller struct {
@ -91,7 +91,7 @@ func (i *LocalInstaller) installFromDirectory() error {
return err return err
} }
if !stat.IsDir() { if !stat.IsDir() {
return ErrPluginNotAFolder return ErrPluginNotADirectory
} }
if !isPlugin(i.Source) { if !isPlugin(i.Source) {

@ -64,7 +64,7 @@ func TestLocalInstallerNotAFolder(t *testing.T) {
if err == nil { if err == nil {
t.Fatal("expected error") t.Fatal("expected error")
} }
if err != ErrPluginNotAFolder { if err != ErrPluginNotADirectory {
t.Fatalf("expected error to equal: %q", err) t.Fatalf("expected error to equal: %q", err)
} }
} }

Loading…
Cancel
Save