Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: fix core dump if the terminal is closed while bottom is open #1230

Merged
merged 2 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/),
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

## Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bottom"
version = "0.9.3"
version = "0.9.4"
authors = ["Clement Tsang <[email protected]>"]
edition = "2021"
repository = "https://github.com/ClementTsang/bottom"
Expand Down Expand Up @@ -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]
Expand Down
29 changes: 13 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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) {
Expand Down