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

Return error message when using --untag with nonexistent tag #880

Merged
merged 4 commits into from
Jun 11, 2020

Conversation

danielhelfand
Copy link
Contributor

@danielhelfand danielhelfand commented Jun 8, 2020

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:

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 --no-wait

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

@googlebot googlebot added the cla: yes Indicates the PR's author has signed the CLA. label Jun 8, 2020
Copy link
Contributor

@knative-prow-robot knative-prow-robot left a 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.

@knative-prow-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

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.

@knative-prow-robot knative-prow-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 8, 2020
@rhuss
Copy link
Contributor

rhuss commented Jun 9, 2020

/ok-to-test

@knative-prow-robot knative-prow-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jun 9, 2020
_, _, _, err := fakeServiceUpdate(orig, []string{
"service", "update", "foo", "--untag", "foo", "--no-wait"})

assert.Error(t, err, "Error: tag foo does not exist")
Copy link
Contributor

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.

Copy link
Contributor Author

@danielhelfand danielhelfand Jun 9, 2020

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.

Copy link
Contributor

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

client/cmd/kn/main.go

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.

Copy link
Contributor

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.

Copy link
Collaborator

@navidshaikh navidshaikh left a 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.

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 9, 2020
Copy link
Contributor

@rhuss rhuss left a 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.

pkg/kn/traffic/compute.go Outdated Show resolved Hide resolved
pkg/kn/traffic/compute_test.go Outdated Show resolved Hide resolved
@danielhelfand
Copy link
Contributor Author

/retest

@danielhelfand danielhelfand force-pushed the issue_874 branch 3 times, most recently from e957ff8 to 1baee91 Compare June 9, 2020 14:43
Copy link
Contributor

@rhuss rhuss left a 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

Copy link
Collaborator

@navidshaikh navidshaikh left a 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

pkg/kn/traffic/compute.go Outdated Show resolved Hide resolved
@knative-prow-robot knative-prow-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 10, 2020
@danielhelfand danielhelfand force-pushed the issue_874 branch 2 times, most recently from 94d3895 to 3ae19db Compare June 10, 2020 16:33
@danielhelfand
Copy link
Contributor Author

/retest

@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-client-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/kn/commands/service/update.go 85.5% 90.9% 5.5

@danielhelfand
Copy link
Contributor Author

danielhelfand commented Jun 10, 2020

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

Added e2e tests to verify output of error message under service_test.go as well as state of revisions when error occurs under traffic_split_test.go. Also made CHANGELOG entry.

@danielhelfand
Copy link
Contributor Author

/test pull-knative-client-integration-tests

Copy link
Contributor

@rhuss rhuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks !

/lgtm
/approve

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jun 11, 2020
@knative-prow-robot
Copy link
Contributor

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

@knative-prow-robot knative-prow-robot merged commit 3f146b1 into knative:master Jun 11, 2020
rhuss pushed a commit to rhuss/knative-client that referenced this pull request Jun 14, 2020
…#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
@navidshaikh navidshaikh added the backport/candidate Consider this PR to be backported to the release branch label Jun 15, 2020
@navidshaikh navidshaikh changed the title Return Error Message from Using --untag with Nonexistent Tag Return error message when using --untag with nonexistent tag Jun 16, 2020
navidshaikh pushed a commit to navidshaikh/client that referenced this pull request Jun 16, 2020
…#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
navidshaikh pushed a commit to navidshaikh/client that referenced this pull request Jun 16, 2020
 - Updates the vendor/modules.txt
 - Update CHANGELOG
 - Squashed commits for
   knative#866
   knative#880
navidshaikh added a commit to navidshaikh/client that referenced this pull request Jun 16, 2020
 - Updates the vendor/modules.txt
 - Update CHANGELOG
 - Squashed commits for
   knative#866
   knative#880
navidshaikh added a commit to navidshaikh/client that referenced this pull request Jun 16, 2020
 - Updates the vendor/modules.txt
 - Update CHANGELOG
 - Squashed commits for
   knative#866
   knative#880
   knative#883
knative-prow-robot pushed a commit that referenced this pull request Jun 16, 2020
- Updates the vendor/modules.txt
 - Update CHANGELOG
 - Squashed commits for
   #866
   #880
   #883
@navidshaikh navidshaikh added backported-to/0.15 and removed backport/candidate Consider this PR to be backported to the release branch labels Aug 18, 2020
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. cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

traffic tags: Error if requested for removing non-existing tag
7 participants