From cccf0226a53ab9aff1efba3e363e79e994a15164 Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Tue, 27 Jun 2023 01:36:52 -0400 Subject: [PATCH 1/2] 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. --- CHANGELOG.md | 4 ++++ Cargo.lock | 2 +- Cargo.toml | 6 ++---- src/lib.rs | 29 +++++++++++++---------------- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7c54d367..559898c43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.9.3]/[0.10.0] - Unreleased + +## Bug Fixes + ## [0.9.3] - 2023-06-25 ## Bug Fixes diff --git a/Cargo.lock b/Cargo.lock index d8caf1b4d..474cccb16 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -142,7 +142,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bottom" -version = "0.9.3" +version = "0.9.4" dependencies = [ "anyhow", "assert_cmd", diff --git a/Cargo.toml b/Cargo.toml index dfd8b9b2e..8813e73a6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "bottom" -version = "0.9.3" +version = "0.9.4" authors = ["Clement Tsang "] edition = "2021" repository = "https://github.com/ClementTsang/bottom" @@ -133,9 +133,7 @@ filedescriptor = "0.8.2" [dev-dependencies] assert_cmd = "2.0.11" -cargo-husky = { version = "1.5.0", default-features = false, features = [ - "user-hooks", -] } +cargo-husky = { version = "1.5.0", default-features = false, features = ["user-hooks"] } predicates = "3.0.3" [build-dependencies] diff --git a/src/lib.rs b/src/lib.rs index 86d36cb7f..e3249244e 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 '' 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 '' panicked at '{msg}', {panic_info}\n\r{stacktrace}", + )), + ); + } } pub fn update_data(app: &mut App) { From dc3bcf251bf4eeb8b928038735c7ecdc996046a9 Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Tue, 27 Jun 2023 01:39:01 -0400 Subject: [PATCH 2/2] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 559898c43..71c522cbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Bug Fixes +- [#1230](https://github.com/ClementTsang/bottom/pull/1230): Fix core dump if the terminal is closed while bottom is open. + ## [0.9.3] - 2023-06-25 ## Bug Fixes