Closed knadh closed 7 months ago
The cli library itself does not provide any mechanism to do this. You can implement it on your own.
No panics are not suppressed. However After() is added as a deferred function to the command processing logic so it will execute even if Action() panics. That is golang standard behaviour. This allows the defer function to suppress/manage the panic and continue or abort.
Generally you shouldnt be using os.Exit() at all, you either return an err or nil to the corresponding Action()/Before()/After() funcs and the cli library will handle the rest.
However After() is added as a deferred function to the command processing logic so it will execute even if Action() panics
Generally you shouldnt be using os.Exit() at all, you either return an err or nil to the corresponding Action()/Before()/After() funcs and the cli library will handle the rest.
This has to be explicitly stated in the docs then. Will send a docs PR sometime soon. Thank you.
Version: v2.25.7 Related: https://github.com/urfave/cli/issues/451
Hi there.
After()
, as documented, executes regardless of any panics inAction()
functions. Naturally, any business logic inAfter()
that depends on business logic executed by anAction()
will fail.After()
whether anAction()
has failed so that any subsequent business logic doesn't execute?defer/recover
inside everyAction()
and taking over the control flow just becauseAfter()
is designed to execute despite panics may not be ideal.After()
was designed to suppress panics and execute regardless?os.Exit(0)
insideAfter()
which prevented any stack traces from being printed, so it took forever to figure out that there was a panic happening. Should it be explicitly documented thatos.Exit(0)
should not be used at all?Thanks!
Sample code for context (
./app.bin test
)