tirbofish/dropbear
main / crates / dropbear-engine / src / panic.rs · 1622 bytes
crates/dropbear-engine/src/panic.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use std::panic;
#[cfg(not(target_os = "android"))]
use rfd::{MessageDialog, MessageLevel};
/// Creates a new panic hook for crash detection.
pub fn set_hook() {
panic::set_hook(Box::new(|info| {
let msg = if let Some(s) = info.payload().downcast_ref::<&str>() {
*s
} else if let Some(s) = info.payload().downcast_ref::<String>() {
s.as_str()
} else {
"Unknown panic payload"
};
let location = info
.location()
.map(|l| format!("{}:{}", l.file(), l.line()))
.unwrap_or_else(|| "unknown location".to_string());
let full_text = format!(
"The application has encountered a fatal error and must close.\n\n\
Location: {}\nError: {}\n\nPlease report this error to the developers.",
location, msg
);
log::error!(
"PANIC! SHUTDOWN SHUTDOWN SHUT THIS SHIT DOWN\n============================\n{}\n============================",
full_text
);
#[cfg(not(target_os = "android"))]
{
// if let Ok(mut clipboard) = Clipboard::new() {
// let _ = clipboard.set_text(full_text.clone());
// }
let _ = MessageDialog::new()
.set_title("Panic!")
.set_description(&full_text)
.set_level(MessageLevel::Error)
.show();
}
log::error!(
"Additional crash info (backtrace): \n{:#?}",
backtrace::Backtrace::new()
);
std::process::exit(1);
}));
}