tj / commander.js

node.js command-line interfaces made easy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Call to _exit still exits the process, despite registering a callback

febeling opened this issue · comments

Call to _exit still exits the process (e.g. from process.error), despite registering a callback via exitOverride.

https://github.com/tj/commander.js/blame/f1ae2db8e2da01d6efcbfd59cbf82202f864b0c1/lib/command.js#L459-L465

What was the purpose of #1040?

Is the idea that I register a callback, but I have to throw an error from it?

Why isn't the exit skipped over if there's an override?

Commander is not set up to gracefully recover from an error that would normally call process.exit(), it expects processing to stop. So the exitOverride callback still has to terminate the normal program flow, usually by throwing an error but could also be by calling process.exit() with a custom error code.

Ok. Thanks for the quick response. Fwiw, I didn't understand that from reading the docs of exitOverride.

I had a go at making this clearer: #2098

That sets expectations clearly. Thanks for addressing the issue!