fix(console): exit crossterm before printing panic messages #307
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
If the
tokio-console
CLI panics, we will eventually exitcrossterm
'sterminal capturing and return to the user's shell. However, this
currently happens after the panic message is printed. This is because
we
crossterm
in a drop guard that's held inmain
, but panic messagesare printed out before unwinding.
This means that for most panics, the panic message is never actually
displayed --- instead, the console just crashes to a blank screen, and
then returns to the user's shell with no output. Some manual testing
(e.g. putting
panic!("fake panic");
in a few different places)indicates that panics will only be displayed nicely if they occur prior
to the call to
term::init_crossterm()
in the main function.This branch fixes this issue by changing the panic hook to explicitly
exit
crossterm
before printing the panic. This way, panics shouldalways be printed to stdout, regardless of where they occur in the
console. I factored out the code for exiting crossterm's terminal
capturing into a function that's now called in the drop guard and in
the panic hook.
I also added some code for logging the panic using
tracing
. That way,even if we fail to exit crossterm's terminal capturing, but the
console's debug logs are being redirected to a file, we'll still get the
panic in the logs.