Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(console): exit crossterm before printing panic messages (#307)
If the `tokio-console` CLI panics, we will eventually exit `crossterm`'s terminal 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 in `main`, but panic messages are 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 should always 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.
- Loading branch information