Skip to content
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

Merged
merged 6 commits into from
Dec 10, 2019

Conversation

chriskim06
Copy link
Member

Fixes #431

I decided to just use os.IsNotExist on the error rather than errors.Is since there's a package name conflict with the existing github.com/pkg/errors package. I was thinking about using the new %w verb in fmt.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.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Dec 10, 2019
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Dec 10, 2019
@codecov-io
Copy link

codecov-io commented Dec 10, 2019

Codecov Report

Merging #432 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ce716e9...3e82bdb. Read the comment docs.

@ahmetb
Copy link
Member

ahmetb commented Dec 10, 2019

/hold
let's hold off on this until #429 is merged, there's a fair amount of merge conflicts involved.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 10, 2019
@ahmetb
Copy link
Member

ahmetb commented Dec 10, 2019

I decided to just use os.IsNotExist on the error rather than errors.Is since

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.

Comment on lines 95 to 97
if _, ok := installed[name]; ok {
fmt.Fprintf(os.Stderr, "plugin \"%s\" is already installed\n", name)
skipped = true
Copy link
Member

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

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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

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)
Copy link
Member

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.

@ahmetb
Copy link
Member

ahmetb commented Dec 10, 2019

/retitle cmd: Friendly error messages when plugin not found

@k8s-ci-robot k8s-ci-robot changed the title Error messaging cmd: Friendly error messages when plugin not found Dec 10, 2019
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Dec 10, 2019
emove check on installed plugin and use %q and errors.New
@@ -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))
Copy link
Member

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 :)

Copy link
Member Author

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

@ahmetb
Copy link
Member

ahmetb commented Dec 10, 2019

/lgtm
/approve
/hold cancel
I'm cancelling hold b/c now this is simple enough for me to rebase the other pr.

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Dec 10, 2019
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 10, 2019
@k8s-ci-robot k8s-ci-robot merged commit 3b343e8 into kubernetes-sigs:master Dec 10, 2019
@chriskim06 chriskim06 deleted the error-messaging branch June 11, 2020 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
4 participants