How to properly throw an error and exit with a specific exit code? #886
-
For example, when a parse method fails, I want to output an error (using a logger) and exit with an exit code. I can exit using Is there some lifecycle events (similart to those of Nest)? Those need to be enabled using It might be a good idea to somehow abstract this and define the exit codes in Nest Commander and append them to the help of each command. I’d suggest to output them all in global help, but output only a subset of exit codes for (sub-) commands (output only those that are used by a command). However, if we define an exit cope in decorators, we need to reference them in the methods themselves, which might complicate the implementation a bit. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
I have this mentioned in the docs that there's nothing specific that nest-commander does, it's all at the I'll think if there's a way to abstract an error handler out of this to make it easier to work with |
Beta Was this translation helpful? Give feedback.
Yeah, you can access the commander instance (
program
in the above line) via@InjectCommander()
and then usethis.commander.error('Error message', options)