diff --git a/internal/plugin/installer/installer.go b/internal/plugin/installer/installer.go index a6599c443..c7c1a8801 100644 --- a/internal/plugin/installer/installer.go +++ b/internal/plugin/installer/installer.go @@ -139,18 +139,24 @@ func Update(i Installer) error { } // NewForSource determines the correct Installer for the given source. -func NewForSource(source, version string) (Installer, error) { - // Check if source is an OCI registry reference +func NewForSource(source, version string) (installer Installer, err error) { if strings.HasPrefix(source, fmt.Sprintf("%s://", registry.OCIScheme)) { - return NewOCIInstaller(source) - } - // Check if source is a local directory - if isLocalReference(source) { - return NewLocalInstaller(source) + // Source is an OCI registry reference + installer, err = NewOCIInstaller(source) + } else if isLocalReference(source) { + // Source is a local directory + installer, err = NewLocalInstaller(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. diff --git a/internal/plugin/installer/local_installer.go b/internal/plugin/installer/local_installer.go index e02261d59..1c8314282 100644 --- a/internal/plugin/installer/local_installer.go +++ b/internal/plugin/installer/local_installer.go @@ -29,8 +29,8 @@ import ( "helm.sh/helm/v4/pkg/helmpath" ) -// ErrPluginNotAFolder indicates that the plugin path is not a folder. -var ErrPluginNotAFolder = errors.New("expected plugin to be a folder") +// ErrPluginNotADirectory indicates that the plugin path is not a directory. +var ErrPluginNotADirectory = errors.New("expected plugin to be a directory (containing a file 'plugin.yaml')") // LocalInstaller installs plugins from the filesystem. type LocalInstaller struct { @@ -91,7 +91,7 @@ func (i *LocalInstaller) installFromDirectory() error { return err } if !stat.IsDir() { - return ErrPluginNotAFolder + return ErrPluginNotADirectory } if !isPlugin(i.Source) { diff --git a/internal/plugin/installer/local_installer_test.go b/internal/plugin/installer/local_installer_test.go index 189108fdb..2decb695f 100644 --- a/internal/plugin/installer/local_installer_test.go +++ b/internal/plugin/installer/local_installer_test.go @@ -64,7 +64,7 @@ func TestLocalInstallerNotAFolder(t *testing.T) { if err == nil { t.Fatal("expected error") } - if err != ErrPluginNotAFolder { + if err != ErrPluginNotADirectory { t.Fatalf("expected error to equal: %q", err) } }