-
Notifications
You must be signed in to change notification settings - Fork 67
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
🙋 Option to print the report #62
Comments
Maybe not ideal, but you could get the filename via handle_dump, and then read it and display it to the user. Another option is to use code similar to #55 (comment) and not use human_panic. Instead of logging to a file you just build and use the string. Then you can actually get the panic message as well. For reference, this is code I'm using in my own project: use std::panic::{self, PanicInfo};
use backtrace::Backtrace;
pub fn setup() {
panic::set_hook(Box::new(move |info: &PanicInfo| {
let mut msg = String::new();
let os = if cfg!(target_os = "windows") {
"Windows"
} else if cfg!(target_os = "linux") {
"Linux"
} else if cfg!(target_os = "macos") {
"Mac OS"
} else if cfg!(target_os = "android") {
"Android"
} else {
"Unknown"
};
msg.push_str(&format!("Name: {}\n", env!("CARGO_PKG_NAME")));
msg.push_str(&format!("Version: {}\n", env!("CARGO_PKG_VERSION")));
msg.push_str(&format!("Operating System: {}\n", os));
if let Some(inner) = info.payload().downcast_ref::<&str>() {
msg.push_str(&format!("Cause: {}.\n", &inner));
}
match info.location() {
Some(location) => msg.push_str(&format!(
"Location: in file '{}' at line {}\n",
location.file(),
location.line()
)),
None => msg.push_str("Panic location unknown.\n"),
};
msg.push_str(&format!("Message: {}\n", info));
msg.push_str(&format!("\n{:#?}\n", Backtrace::new()));
// Do something with msg...
}));
} |
thanks @kdar this is really helpful, will try this out |
While on desktop applications it makes sense to store the crash report in a file, on mobile devices it can be challenging to actually find the report file, especially for end users. So for these cases I would like to print the whole report, after message, such that it is easier to report. Is this sth you would consider? Alternatively having a hook to customize the file writing would likely solve this issue as well. Thank you
The text was updated successfully, but these errors were encountered: