-
Notifications
You must be signed in to change notification settings - Fork 263
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
Return error message when using --untag with nonexistent tag #880
Conversation
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.
@danielhelfand: 0 warnings.
In response to this:
Description
This pull request returns an error message when using
kn service update serviceName --untag tagName
on a tag that does not exist.The error returned by
kn
will be as follows, but I am open to any change with regard to the message:Error: tag tagName does not exist
In the event multiple nonexistent tags are specified,
kn
will return multiple errors:kn service update serviceName --untag tagName --untag tagName2 Error: tag tagName does not exist Error: tag tagName2 does not exist
If a tag that does exist is specified with a nonexistent tag, the error will be displayed and no update will be made.
Please let me know if this should warrant an e2e test as well.
Reference
Fixes #874
/lint
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
Hi @danielhelfand. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/ok-to-test |
_, _, _, err := fakeServiceUpdate(orig, []string{ | ||
"service", "update", "foo", "--untag", "foo", "--no-wait"}) | ||
|
||
assert.Error(t, err, "Error: tag foo does not exist") |
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'd suggest to change this to (please add the import, too, if missing0:
assert.Assert(t, util.ContainsAll(err.Error(), "tag", "foo", "not exist"))
It's always very fragile to assert on the exact wording of something, which might slight improvements tedious to work on (as then always a test needs to be fixed). Instead, just check that the important context information is contained in the error message. This focus also having good error message which as much context information as possible to help a user to understand and fix the error. E.g. Here you could also add the service name which would help the user to understand which service you wanted to tag. The more context, the better.
Also, please use error message according to the golang standard: Starting lower case, no punctuation at the need. The "Error:" prefix is also redundant here (its an error anyway), and in fact the top-level routine which prints the error will add the error prefix anyway. So better remove it here, too.
We have an issues open (not sure where), where we want to check for all error messages to be consistently following this rule. Might be a good exercise to automate that and make it part of the build process.
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.
Just to clarify here, the error:
prefix won't be added unless included in the message it seems:
./kn service update hello --untag foo --no-wait
tag(s) foo not present for any revisions of service hello
If you remove silenceErrors
, Cobra will handle errors without needing to print the error in main.go
as is done now:
./kn service update hello --untag foo
Error: tag(s) foo not present for any revisions of service hello
I think it makes sense to revisit this by changing how kn
handles errors.
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.
Totally agree, that a consistent error handling is missing, but for consistency's sake, I think there should be a single point which prepares an error message for print out.
In fact, in the refactoring in #877 there is a single exit point in case of a custom error, that now adds the appropriate prefix -->
Lines 38 to 41 in a71cc3f
if err != nil { | |
fmt.Fprintf(os.Stderr, "Error: %v\n", err) | |
// This is the only point from where to exit when an error occurs | |
os.Exit(1) |
We can more error messaging mangling at this point (like uppercasing the first letter), but if we assume that the change above gets merged, then we should already avoid an Error:
prefix.
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.
But don't let that block this PR as we have to go over all error messages later anyway.
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.
thanks @danielhelfand !
looks good to me!
We should add e2e test.
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.
Thanks ! looks good, but I have some suggestion regarding the wording of the error messages.
/retest |
e957ff8
to
1baee91
Compare
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.
Thanks a lot !
Looks good to me, but as @navidshaikh mentioned we should add an extra e2e test for this error handling to https://github.com/knative/client/blob/master/test/e2e/traffic_split_test.go and also an entry to https://github.com/knative/client/blob/master/CHANGELOG.adoc
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.
suggested minor nit for return value from function
94d3895
to
3ae19db
Compare
/retest |
The following is the coverage report on the affected files.
|
Added e2e tests to verify output of error message under |
/test pull-knative-client-integration-tests |
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.
thanks !
/lgtm
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: danielhelfand, navidshaikh, rhuss 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 |
…#880) * return error message from using --untag with nonexistent tag * improve err message for --untag and add e2e test * change untagRevision to return bool and add traffic e2e tests * update changelog
…#880) * return error message from using --untag with nonexistent tag * improve err message for --untag and add e2e test * change untagRevision to return bool and add traffic e2e tests * update changelog
- Updates the vendor/modules.txt - Update CHANGELOG - Squashed commits for knative#866 knative#880
- Updates the vendor/modules.txt - Update CHANGELOG - Squashed commits for knative#866 knative#880
- Updates the vendor/modules.txt - Update CHANGELOG - Squashed commits for knative#866 knative#880 knative#883
Description
This pull request returns an error message when using
kn service update serviceName --untag tagName --no-wait
on a tag that does not exist.The error returned by
kn
will be as follows, but I am open to any change with regard to the message:In the event multiple nonexistent tags are specified,
kn
will return multiple errors:If a tag that does exist is specified with a nonexistent tag, the error will be displayed and no update will be made.
Please let me know if this should warrant an e2e test as well.
Reference
Fixes #874
/lint