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
This commit is contained in:
Clement Tsang 2023-06-27 01:57:32 -04:00 committed by GitHub
parent 0902abf6f9
commit aa191a981d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 21 deletions

View File

@ -5,6 +5,12 @@ 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/), 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). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.9.3]/[0.10.0] - Unreleased
## 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 ## [0.9.3] - 2023-06-25
## Bug Fixes ## Bug Fixes

2
Cargo.lock generated
View File

@ -142,7 +142,7 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]] [[package]]
name = "bottom" name = "bottom"
version = "0.9.3" version = "0.9.4"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"assert_cmd", "assert_cmd",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "bottom" name = "bottom"
version = "0.9.3" version = "0.9.4"
authors = ["Clement Tsang <cjhtsang@uwaterloo.ca>"] authors = ["Clement Tsang <cjhtsang@uwaterloo.ca>"]
edition = "2021" edition = "2021"
repository = "https://github.com/ClementTsang/bottom" repository = "https://github.com/ClementTsang/bottom"
@ -133,9 +133,7 @@ filedescriptor = "0.8.2"
[dev-dependencies] [dev-dependencies]
assert_cmd = "2.0.11" assert_cmd = "2.0.11"
cargo-husky = { version = "1.5.0", default-features = false, features = [ cargo-husky = { version = "1.5.0", default-features = false, features = ["user-hooks"] }
"user-hooks",
] }
predicates = "3.0.3" predicates = "3.0.3"
[build-dependencies] [build-dependencies]

View File

@ -293,7 +293,7 @@ pub fn check_if_terminal() {
} }
/// A panic hook to properly restore the terminal in the case of a panic. /// 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<'_>) { pub fn panic_hook(panic_info: &PanicInfo<'_>) {
let mut stdout = stdout(); 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(); let _ = disable_raw_mode();
execute!( let _ = execute!(
stdout, stdout,
DisableBracketedPaste, DisableBracketedPaste,
DisableMouseCapture, DisableMouseCapture,
LeaveAlternateScreen LeaveAlternateScreen
) );
.unwrap();
// Print stack trace. Must be done after! // Print stack trace. Must be done after!
execute!( if let Some(panic_info) = panic_info.location() {
stdout, let _ = execute!(
Print(format!( stdout,
"thread '<unnamed>' panicked at '{}', {}\n\r{}", Print(format!(
msg, "thread '<unnamed>' panicked at '{msg}', {panic_info}\n\r{stacktrace}",
panic_info.location().unwrap(), )),
stacktrace );
)), }
)
.unwrap();
} }
pub fn update_data(app: &mut App) { pub fn update_data(app: &mut App) {