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
Better error handling for parseAsync() #1144
Comments
Commander sees a command that does not exist as an argument that you don't happen to handle. (Related collection of issues: #1088) The current approach is to add a custom event listener and there is an example in README:
See |
I didn't know that it was the correct behavior for when calling a command that does not exist. const program = new Command();
program.command("test <req>")
.action(async () => {
// do some async work
});
program.exitOverride()
.parseAsync(process.argv)
.catch(error => {
// not reached on invalid command (missing req)
}); |
To get the exitOverride to apply to the subcommand too, define it before adding the command. Then to catch the error I think you need to be in an async context when it is thrown.
|
It works, thank you for your help. |
Hello,
When using the new method
parseAsync()
it seems that it is not possible to override the default error handling behavior :parseAsync()
does not throw an error or exit the process, the promise resolveIt should be possible to override those default behaviors in order to catch an error like with the sync
parse()
method.The text was updated successfully, but these errors were encountered: