From 3b343e8f9bef4380c50c2dc6fb05855a1eeb955f Mon Sep 17 00:00:00 2001 From: Chris Kim Date: Tue, 10 Dec 2019 12:22:06 -0800 Subject: [PATCH] cmd: Friendly error messages when plugin not found (#432) * Update error message when upgrading plugin that isn't in the manifest Also remove line from run-tests.sh for file that was deleted in kubernetes-sigs@e37ee1d#diff-d78b6f30225cdc811adfe8d4e7c9fd34 * Update messaging when installing non-existent plugin * Skip installing plugins that are already installed * Use os.IsNotExist * Code review changes emove check on installed plugin and use %q and errors.New * Use errors.Errorf --- cmd/krew/cmd/install.go | 3 +++ cmd/krew/cmd/upgrade.go | 3 +++ hack/run-tests.sh | 3 --- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/krew/cmd/install.go b/cmd/krew/cmd/install.go index 8c7fb137..66b7fd95 100644 --- a/cmd/krew/cmd/install.go +++ b/cmd/krew/cmd/install.go @@ -89,6 +89,9 @@ Remarks: for _, name := range pluginNames { plugin, err := indexscanner.LoadPluginFileFromFS(paths.IndexPluginsPath(), name) if err != nil { + if os.IsNotExist(err) { + return errors.Errorf("plugin %q does not exist in the plugin index", name) + } return errors.Wrapf(err, "failed to load plugin %q from the index", name) } install = append(install, plugin) diff --git a/cmd/krew/cmd/upgrade.go b/cmd/krew/cmd/upgrade.go index 09119546..94287836 100644 --- a/cmd/krew/cmd/upgrade.go +++ b/cmd/krew/cmd/upgrade.go @@ -64,6 +64,9 @@ kubectl krew upgrade foo bar"`, for _, name := range pluginNames { plugin, err := indexscanner.LoadPluginFileFromFS(paths.IndexPluginsPath(), name) if err != nil { + if os.IsNotExist(err) { + return errors.Errorf("plugin %q does not exist in the plugin index", name) + } return errors.Wrapf(err, "failed to load the plugin manifest for plugin %s", name) } diff --git a/hack/run-tests.sh b/hack/run-tests.sh index 75780dac..a5bacee8 100755 --- a/hack/run-tests.sh +++ b/hack/run-tests.sh @@ -40,9 +40,6 @@ trap print_status EXIT print_with_color "$color_blue" 'Checking boilerplate' "$SCRIPTDIR"/verify-boilerplate.sh -print_with_color "$color_blue" 'Running gofmt' -"$SCRIPTDIR"/verify-gofmt.sh - print_with_color "$color_blue" 'Running tests' go test -short -race sigs.k8s.io/krew/...