-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b1a8e1
commit 1beff3e
Showing
8 changed files
with
139 additions
and
80 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# test_that("panic doesn't crash R session", { | ||
# code <- r"( | ||
# use savvy::savvy; | ||
# | ||
# #[allow(unreachable_code)] | ||
# #[savvy] | ||
# fn try_panic() -> savvy::Result<()> { | ||
# panic!("safe"); | ||
# Ok(()) | ||
# } | ||
# )" | ||
# | ||
# savvy_override <- list(savvy = list(path = file.path(getwd(), "../../../"))) | ||
# savvy::savvy_source(code, use_cache_dir = TRUE, dependencies = savvy_override) | ||
# | ||
# expect_error(try_panic()) | ||
# }) |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
pub fn panic_hook(panic_info: &std::panic::PanicInfo) { | ||
// Forcibly captures a full backtrace regardless of RUST_BACKTRACE | ||
let bt = std::backtrace::Backtrace::force_capture().to_string(); | ||
|
||
// Since savvy generates many wrappers, the backtrace is boringly deep. Try | ||
// cutting the uninteresting part. | ||
let bt_short = bt | ||
.lines() | ||
.skip_while(|line| !line.contains("std::panic::catch_unwind")) | ||
// C stacks are not visible from Rust's side and shown as `<unknown>`. | ||
.take_while(|line| !line.contains("<unknown>")) | ||
.collect::<Vec<&str>>() | ||
.join("\n"); | ||
|
||
let bt = if bt_short.is_empty() { bt } else { bt_short }; | ||
|
||
crate::io::r_eprint( | ||
&format!( | ||
"panic occured! | ||
Original message: | ||
{panic_info} | ||
Backtrace: | ||
...snip... (frames of savvy framework) | ||
{bt} | ||
...snip... (frames of R) | ||
" | ||
), | ||
true, | ||
); | ||
} |