fix: show panic output when fullscreen app panic#114
Open
hsqStephenZhang wants to merge 2 commits intoccbrown:mainfrom
Open
fix: show panic output when fullscreen app panic#114hsqStephenZhang wants to merge 2 commits intoccbrown:mainfrom
hsqStephenZhang wants to merge 2 commits intoccbrown:mainfrom
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #114 +/- ##
=======================================
Coverage 91.58% 91.58%
=======================================
Files 29 29
Lines 4715 4715
Branches 4715 4715
=======================================
Hits 4318 4318
Misses 309 309
Partials 88 88 🚀 New features to boost your workflow:
|
Owner
|
Thanks for the PR! I like the idea, but I don't love exposing crossterm and requiring users to use it directly. If the stack is allowed to unwind, fullscreen will be exited normally, so I wonder if something like this would be better: diff --git a/examples/fullscreen.rs b/examples/fullscreen.rs
index 41d4424..ebf87fb 100644
--- a/examples/fullscreen.rs
+++ b/examples/fullscreen.rs
@@ -1,6 +1,10 @@
use chrono::Local;
use iocraft::prelude::*;
-use std::time::Duration;
+use std::{backtrace::Backtrace, cell::Cell, time::Duration};
+
+thread_local! {
+ static BACKTRACE: Cell<Option<Backtrace>> = const { Cell::new(None) };
+}
#[component]
fn Example(mut hooks: Hooks) -> impl Into<AnyElement<'static>> {
@@ -21,6 +25,7 @@ fn Example(mut hooks: Hooks) -> impl Into<AnyElement<'static>> {
TerminalEvent::Key(KeyEvent { code, kind, .. }) if kind != KeyEventKind::Release => {
match code {
KeyCode::Char('q') => should_exit.set(true),
+ KeyCode::Char('p') => panic!("oh no!"),
_ => {}
}
}
@@ -54,11 +59,23 @@ fn Example(mut hooks: Hooks) -> impl Into<AnyElement<'static>> {
) {
Text(content: format!("Current Time: {}", time.get().format("%r")))
}
- Text(content: "Press \"q\" to quit.")
+ Text(content: "Press \"q\" to quit or \"p\" to panic.")
}
}
}
fn main() {
- smol::block_on(element!(Example).fullscreen()).unwrap();
+ std::panic::set_hook(Box::new(|_| {
+ let trace = Backtrace::capture();
+ BACKTRACE.with(move |b| b.set(Some(trace)));
+ }));
+
+ if std::panic::catch_unwind(|| {
+ smol::block_on(element!(Example).fullscreen()).unwrap();
+ })
+ .is_err()
+ {
+ let b = BACKTRACE.with(|b| b.take()).unwrap();
+ println!("panic:\n\n{b}");
+ }
} |
Contributor
Author
|
yeah agreed, catching and print the panic explictly info a better approach without exposing crossterm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What It Does
setup panic handler before enter fullscreen mode
in the handler, leave current screen before printing the backtrace, so that panic output own't get lost along with that screen
Related Issues
#103