-
Notifications
You must be signed in to change notification settings - Fork 369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd: Friendly error messages when plugin not found #432
cmd: Friendly error messages when plugin not found #432
Conversation
Also remove line from run-tests.sh for file that was deleted in kubernetes-sigs/krew@e37ee1d#diff-d78b6f30225cdc811adfe8d4e7c9fd34
Codecov Report
@@ Coverage Diff @@
## master #432 +/- ##
=======================================
Coverage 56.35% 56.35%
=======================================
Files 19 19
Lines 928 928
=======================================
Hits 523 523
Misses 350 350
Partials 55 55 Continue to review full report at Codecov.
|
/hold |
I think this wouldn't work currently, because (1) github/pkg/errors.Wrap doesn't wrap the errors in a way the new go1.13 errors.Is() can use (2) the rest of the codebase must migrate to the errors package properly before we start incorporating parts of it. |
cmd/krew/cmd/install.go
Outdated
if _, ok := installed[name]; ok { | ||
fmt.Fprintf(os.Stderr, "plugin \"%s\" is already installed\n", name) | ||
skipped = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what this part does. We already have the skipping behavior implemented (see below), we can't implement it again like this. I don't see how this changes anything?
$ kubectl krew install krew
Updated the local copy of plugin index.
Installing plugin: krew
W1209 19:07:29.190869 69309 install.go:124] Skipping plugin "krew", it is already installed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it helps us not look up the deleted manifest of a plugin that's already installed. I don't think we need this, the error you added below does a proper job.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that skipping the manifest lookup for an already installed plugin and displaying a different message was what we wanted for this based on your comment here:
... we try to load manifest from fs again, I wonder why. we should be treating it like ErrAlreadyInstalled and say it's already installed
If its not necessary I can totally remove it, but I thought it seemed a little nicer.
Another reason I added it was for the case when the plugin(s) that are being installed don't exist so that the help message doesn't get printed. It felt out of place to show that as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think it's making the code unnecessarily more complex and it solves a small problem that rarely occurs if ever (installing an installed plugin directly by name, after its manifest is which occurred after installing it for the first time). Let's abandon this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I'll remove it
cmd/krew/cmd/install.go
Outdated
plugin, err := indexscanner.LoadPluginFileFromFS(paths.IndexPluginsPath(), name) | ||
if err != nil { | ||
if os.IsNotExist(err) { | ||
return fmt.Errorf("plugin \"%s\" does not exist in the plugin index", name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use %q.
and also please use errors.New
, as it creates a stacktrace.
/retitle cmd: Friendly error messages when plugin not found |
emove check on installed plugin and use %q and errors.New
3f08f70
to
6700aa0
Compare
cmd/krew/cmd/install.go
Outdated
@@ -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.New(fmt.Sprintf("plugin %q does not exist in the plugin index", name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry for back and forth but you can use errors.Errorf for this :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, I'll make the change tomorrow
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahmetb, chriskim06 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Fixes #431
I decided to just use
os.IsNotExist
on the error rather thanerrors.Is
since there's a package name conflict with the existinggithub.com/pkg/errors
package. I was thinking about using the new %w verb infmt.Errorf
but noticed that you lose stack trace info when setting the log level. There's an existing issue, #414, that is open to consider using 1.13 logging so I figured I'd use this for now and we could change it when the other issue gets figured out.