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

Refactor antctl error message #509

Merged
merged 1 commit into from
Mar 19, 2020
Merged

Conversation

lzhecheng
Copy link
Contributor

issue #506

Turn error message into a more friendly one:
Error: NotFound: resource "resouce name" not found

@antrea-bot
Copy link
Collaborator

Thanks for your PR.
Unit tests and code linters are run automatically every time the PR is updated.
E2e, conformance and network policy tests can only be triggered by a member of the vmware-tanzu organization. Regular contributors to the project should join the org.

The following commands are available:

  • /test-e2e: to trigger e2e tests.
  • /skip-e2e: to skip e2e tests.
  • /test-conformance: to trigger conformance tests.
  • /skip-conformance: to skip conformance tests.
  • /test-networkpolicy: to trigger networkpolicy tests.
  • /skip-networkpolicy: to skip networkpolicy tests.
  • /test-all: to trigger all tests.
  • /skip-all: to skip all tests.

These commands can only be run by members of the vmware-tanzu organization.

Copy link
Contributor

@salv-orlando salv-orlando left a comment

Choose a reason for hiding this comment

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

looks good to me. nits inline.

var code int
_ = result.StatusCode(&code)
if err := generate(opt.commandDefinition, opt.args, code); err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

the logic is fine, but it's a bit weird that 'err' is not an error code but the actual return value of the function! Perhaps errMsg could be a better name. (I know this is a bit pedant, sorry...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It makes sense. Code updated.

},
code: http.StatusNotFound,
expected: "NotFound: foo \"bar\" not found",
},
Copy link
Contributor

Choose a reason for hiding this comment

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

more nit: add another case for code != http.StatusNotFound

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a case for error code not considered. As for them, command will get "Unknown error" message.

switch code {
case http.StatusNotFound:
return fmt.Errorf("NotFound: %s \"%s\" not found", cd.use, args["name"])
}
Copy link
Contributor

Choose a reason for hiding this comment

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

what about other error codes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added case for http.StatusInternalServerError and the rest will get Unknown error.

You mentioned this case last time which returns http.StatusBadRequest:

# antctl get pod-interface -A my-pod
Error: error when requesting https://127.0.0.1:10443/podinterface?all-namespaces=true&name=my-pod&namespace=default: the server rejected our request for an unknown reason

But we don't have -A flag now so it is not considered.
These error codes are so far what I found in handlers and we can add more in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

I saw that you added a default case with return fmt.Errorf("Unknown error"), that's what I was looking for

Turn error message into a more friendly one, including http.StatusNotFound, http.StatusInternalServerError.
switch code {
case http.StatusNotFound:
return fmt.Errorf("NotFound: %s \"%s\" not found", cd.use, args["name"])
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I saw that you added a default case with return fmt.Errorf("Unknown error"), that's what I was looking for

@lzhecheng
Copy link
Contributor Author

/test-all

@lzhecheng lzhecheng merged commit 2f7683d into antrea-io:master Mar 19, 2020
@lzhecheng lzhecheng deleted the issue-506 branch March 19, 2020 02:03
ZhangYW18 pushed a commit to ZhangYW18/antrea that referenced this pull request Mar 23, 2020
Turn error message into a more friendly one, including http.StatusNotFound, http.StatusInternalServerError.
ZhangYW18 added a commit to ZhangYW18/antrea that referenced this pull request Mar 23, 2020
ZhangYW18 added a commit to ZhangYW18/antrea that referenced this pull request Mar 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants