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

[CLI] Add graceful error handling for unknown command #494

Conversation

grokify
Copy link
Member

@grokify grokify commented Jul 7, 2018

PR checklist

  • Read the contribution guidelines.
  • Ran the shell script under ./bin/ to update Petstore sample so that CIs can verify the change. (For instance, only need to run ./bin/{LANG}-petstore.sh and ./bin/security/{LANG}-petstore.sh if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in .\bin\windows\.
  • Filed the PR against the correct branch: master, 3.1.x, 4.0.x. Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

Currently, the CLI throws an exception when an unknown command is encountered such as the following for --help as mentioned here: #490

It's hard to figure out the command line options when the software crashes when called with --help.

The uncaught exception will result in the following:

$ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar --help
Exception in thread "main" io.airlift.airline.ParseArgumentsUnexpectedException: Found unexpected parameters: [--help]
	at io.airlift.airline.Cli.validate(Cli.java:148)
	at io.airlift.airline.Cli.parse(Cli.java:116)
	at io.airlift.airline.Cli.parse(Cli.java:97)
	at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:58)

A few people have run into this as mentioned here: airlift/airline#45

--help is the first thing I run on a new command

This PR will return a graceful error for any unknown command by gracefully catching io.airlift.airline.ParseArgumentsUnexpectedException such as the following:

$ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar --help
[error] Found unexpected parameters: [--help]

See 'openapi-generator-cli help' for usage.

A DWIM approach would alias --help to help but this may lead to more issues as we may need to alias all the other commands as well to avoid confusion. This approach returns an nicer error message and encourages the user to learn the correct syntax for the CLI. However, if we decide it is better to alias, I can look into this too.

@wing328 wing328 added this to the 3.1.1 milestone Jul 8, 2018
@wing328
Copy link
Member

wing328 commented Jul 8, 2018

Agreed that aliasing may result in a lot of works and your solution is much better than showing the exception.

@wing328 wing328 merged commit 9103ddb into OpenAPITools:master Jul 8, 2018
A-Joshi pushed a commit to ihsmarkitoss/openapi-generator that referenced this pull request Feb 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants