Skip to content

Commit

Permalink
Improve error information output
Browse files Browse the repository at this point in the history
  • Loading branch information
Systemcluster committed Mar 15, 2024
1 parent 08e8f94 commit e18f6c4
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions startpe/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,27 @@ use versioning::*;
fn main() {
set_hook(Box::<_>::new(move |panic| {
if let Some(message) = panic.payload().downcast_ref::<&str>() {
eprintln!("{}", message);
eprintln!("error: {}", message);
} else if let Some(message) = panic.payload().downcast_ref::<String>() {
eprintln!("{}", message);
eprintln!("error: {}", message);
} else {
eprintln!("{}", panic);
eprintln!("error: {}", panic);
}
#[cfg(windows)]
if let Ok(mut file) = File::create(format!(
"error-{}.txt",
SystemTime::now()
{
let now = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap_or_default()
.as_secs()
)) {
let _ = writeln!(file, "{}", panic);
.unwrap_or_default();
if let Ok(mut file) = File::create(format!(
"error-{}-{}.txt",
now.as_secs(),
now.subsec_millis()
)) {
let _ = writeln!(file, "An error occurred while starting the application.");
let _ = writeln!(file, "Please report this error to the developers.");
let _ = writeln!(file);
let _ = writeln!(file, "{}", panic);
}
}
}));

Expand Down

0 comments on commit e18f6c4

Please sign in to comment.