diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2023-06-27 01:57:32 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-27 01:57:32 -0400 |
commit | aa191a981d19cb47534821ecc7400182ed23874a (patch) | |
tree | 0bacc448845d84995d242c9eb288110053bb1cda /src/lib.rs | |
parent | 0902abf6f93284cf7a82eef80e703f541836e29e (diff) |
bug: fix core dump if the terminal is closed while bottom is open (#1230)
* bug: fix core dump if the terminal is closed
The cause was:
- bottom thinks it's panicking if the terminal is closed.
- The panic hook tried to print out to the terminal - but the terminal
was closed! It would unwrap and thus panic even harder.
- To solve this, we just make the panic hook calls not unwrap, since
honestly if they fail it's whatever as far as I understand it.
* update changelog
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 29 |
1 files changed, 13 insertions, 16 deletions
@@ -293,7 +293,7 @@ pub fn check_if_terminal() { } /// A panic hook to properly restore the terminal in the case of a panic. -/// Based on [spotify-tui's implementation](https://github.com/Rigellute/spotify-tui/blob/master/src/main.rs). +/// Originally based on [spotify-tui's implementation](https://github.com/Rigellute/spotify-tui/blob/master/src/main.rs). pub fn panic_hook(panic_info: &PanicInfo<'_>) { let mut stdout = stdout(); @@ -305,28 +305,25 @@ pub fn panic_hook(panic_info: &PanicInfo<'_>) { }, }; - let stacktrace: String = format!("{:?}", backtrace::Backtrace::new()); + let stacktrace = format!("{:?}", backtrace::Backtrace::new()); - disable_raw_mode().unwrap(); - execute!( + let _ = disable_raw_mode(); + let _ = execute!( stdout, DisableBracketedPaste, DisableMouseCapture, LeaveAlternateScreen - ) - .unwrap(); + ); // Print stack trace. Must be done after! - execute!( - stdout, - Print(format!( - "thread '<unnamed>' panicked at '{}', {}\n\r{}", - msg, - panic_info.location().unwrap(), - stacktrace - )), - ) - .unwrap(); + if let Some(panic_info) = panic_info.location() { + let _ = execute!( + stdout, + Print(format!( + "thread '<unnamed>' panicked at '{msg}', {panic_info}\n\r{stacktrace}", + )), + ); + } } pub fn update_data(app: &mut App) { |