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
Help is shown if async command handler fails #2394
Comments
Macil
changed the title
Help is shown if command async handler fails
Help is shown if async command handler fails
Mar 21, 2024
I didn't work out why it works this way by default, but looks like it is deliberate and you can change the behaviour. https://github.com/yargs/yargs/blob/main/docs/advanced.md#handling-async-errors
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When an async command handler throws an error (more specifically: when a command handler returns a promise that rejects), yargs shows the help output, even though the user specified a valid command and options. As a user I find this really confusing because it seems to imply that I mistyped a command. I don't expect to see the help output if a command fails for a reason other than me passing an invalid argument, like if a command fails from a connection error.
Help output is not shown when a non-async command handler throws an errors. This matches my expectations. I'd expect async command handlers would work like this too.
Example program with an async command handler that throws an error:
Using yargs 17.7.2 and node v20.11.1, v21.7.1.
The text was updated successfully, but these errors were encountered: