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 error message improvements #172

Merged

Conversation

jimschubert
Copy link
Member

@jimschubert jimschubert commented May 29, 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: Default: master.
  • Copied the technical committee to review the pull request if your PR is targeting a particular programming language.

Description of the PR

Errors in Generate/Validate print to stderr/exit 1

Generate and Validate exposed exceptions rather than user-friendly
messages when an error occurred. In generate, this could happen for
numerous reasons, but the most likely is a user typing (or guessing) an
invalid generator name. In Validate, an error was exposed if there were
any validation errors in a spec.

New behavior:

  • Generate now exposes a typed exception when a generator cannot be
    loaded by name. This allows consistent messaging for load failures.
  • Generate now presents guidance on failure (check the spelling and try
    again). This is purely a usability improvement.
  • Validate now writes validation errors to stderr and exits with code 1.
    Improve err messages: config-help/required opts.
  • config-help now presents same error for invalid generator names as the
    'generate' command.
  • Options which are required, and those which require a value, now present
    a user-friendly hint at the error and exit with code 1 (rather than an
    uncaught exception).

Examples

$ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar config-help -g asdf
Can't load config class with name 'asdf'
Available:
ada
…(removed)
typescript-node

[error] Check the spelling of the generator's name and try again.
$ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i ~/temp/specs/petstore-v3.0.yaml -g php2
Can't load config class with name 'php2'
Available:
ada
…(removed)
typescript-node

[error] Check the spelling of the generator's name and try again.
$ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar validate -i ~/temp/specs/petstore-v3.0-invalid.yaml
Validating spec (/Users/jim/temp/specs/petstore-v3.0-invalid.yaml)

	- attribute info is missing

[error] Spec is invalid.
$ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i ~/temp/specs/petstore-v3.0.yaml
[error] A generator name (--generator-name / -g) is required.
$ java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i ~/temp/specs/petstore-v3.0.yaml -g
[error] Required values for option 'generator name' not provided

All of the above examples exit with status 1.

See #167

Generate and Validate exposed exceptions rather than user-friendly
messages when an error occurred. In generate, this could happen for
numerous reasons, but the most likely is a user typing (or guessing) an
invalid generator name. In Validate, an error was exposed if there were
any validation errors in a spec.

New behavior:

* Generate now exposes a typed exception when a generator cannot be
  loaded by name. This allows consistent messaging for load failures.
* Generate now presents guidance on failure (check the spelling and try
  again). This is purely a usability improvement.
* Validate now writes validation errors to stderr and exits with code 1.
config-help now presents same error for invalid generator names as the
'generate' command.

Options which are required, and those which require a value, now present
a user-friendly hint at the error and exit with code 1 (rather than an
uncaught exception).
@jimschubert
Copy link
Member Author

We don't really have a usability-related label, so I've tagged this Enhancement: General + OpenAPI CLI.

@wing328
Copy link
Member

wing328 commented May 29, 2018

@jimschubert please feel free to create the "Enhancement: Usability" label 👍

Copy link
Member

@wing328 wing328 left a comment

Choose a reason for hiding this comment

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

Looks much better 👍

Copy link
Contributor

@ackintosh ackintosh 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, too. Thanks ✨

@wing328 wing328 merged commit f042132 into OpenAPITools:master May 29, 2018
@jimschubert jimschubert deleted the cli-error-message-improvements branch May 29, 2018 10:42
@wing328 wing328 added this to the 3.0.1 milestone Jun 17, 2018
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.

3 participants