summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2023-06-27 01:57:32 -0400
committerGitHub <noreply@github.com>2023-06-27 01:57:32 -0400
commitaa191a981d19cb47534821ecc7400182ed23874a (patch)
tree0bacc448845d84995d242c9eb288110053bb1cda /src/lib.rs
parent0902abf6f93284cf7a82eef80e703f541836e29e (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.rs29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 86d36cb7..e3249244 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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) {