load arbitrary model data
This commit is contained in:
parent
a853c24bc3
commit
cae3b40541
11 changed files with 3022 additions and 314 deletions
|
@ -1,3 +1,4 @@
|
|||
use std::error::Error;
|
||||
use std::fmt::Write as FmtWrite;
|
||||
use std::mem;
|
||||
|
||||
|
@ -8,50 +9,43 @@ use regex::Regex;
|
|||
static INIT: parking_lot::Once = Once::new();
|
||||
|
||||
pub fn set_panic_hook() {
|
||||
use std::io::Write;
|
||||
|
||||
use colored::Colorize;
|
||||
|
||||
use crate::workspace;
|
||||
|
||||
INIT.call_once(|| {
|
||||
let default_hook = std::panic::take_hook();
|
||||
std::panic::set_hook(Box::new(move |info| {
|
||||
let log_path = workspace::get_working_dir().unwrap_or_else(|_| {
|
||||
if let Err(e) = process_panic(info) {
|
||||
eprintln!("Error in panic hook: {}", e);
|
||||
default_hook(info);
|
||||
std::process::exit(0);
|
||||
});
|
||||
if !log_path.exists() {
|
||||
std::fs::create_dir_all(&log_path).unwrap_or_else(|_| {
|
||||
default_hook(info);
|
||||
std::process::exit(0);
|
||||
});
|
||||
}
|
||||
let log_path = log_path.join("panic.log");
|
||||
std::process::exit(0);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
let mut file = std::fs::File::create(&log_path).unwrap_or_else(|_| {
|
||||
default_hook(info);
|
||||
std::process::exit(0);
|
||||
});
|
||||
let payload = info.payload();
|
||||
let payload_str = if let Some(s) = payload.downcast_ref::<&str>() {
|
||||
*s
|
||||
} else if let Some(s) = payload.downcast_ref::<String>() {
|
||||
s
|
||||
} else {
|
||||
"<non-string panic payload>"
|
||||
};
|
||||
fn process_panic(info: &std::panic::PanicHookInfo<'_>) -> Result<(), Box<dyn Error>> {
|
||||
use crate::workspace;
|
||||
use colored::Colorize;
|
||||
use std::io::Write;
|
||||
|
||||
writeln!(file, "{}", payload_str).unwrap_or_else(|_| {
|
||||
default_hook(info);
|
||||
std::process::exit(0);
|
||||
});
|
||||
writeln!(file, "{}", render_backtrace().sanitize_path()).unwrap_or_else(|_| {
|
||||
default_hook(info);
|
||||
std::process::exit(0);
|
||||
});
|
||||
let log_dir = workspace::get_working_dir()?;
|
||||
if !log_dir.exists() {
|
||||
std::fs::create_dir_all(&log_dir)?;
|
||||
}
|
||||
let log_path = log_dir.join("panic.log");
|
||||
|
||||
let panic_msg = format!(
|
||||
let mut file = std::fs::File::create(&log_path)?;
|
||||
let payload = info.payload();
|
||||
let payload_str = if let Some(s) = payload.downcast_ref::<&str>() {
|
||||
*s
|
||||
} else if let Some(s) = payload.downcast_ref::<String>() {
|
||||
s
|
||||
} else {
|
||||
"<non-string panic payload>"
|
||||
};
|
||||
|
||||
writeln!(file, "{}", payload_str)?;
|
||||
writeln!(file, "{}", render_backtrace().sanitize_path())?;
|
||||
|
||||
let panic_msg = format!(
|
||||
"Zenyx had a problem and crashed. To help us diagnose the problem you can send us a crash report.
|
||||
|
||||
We have generated a report file at \"{}\". Submit an issue or email with the subject of \"Zenyx Crash Report\" and include the report as an attachment.
|
||||
|
@ -63,11 +57,12 @@ https://github.com/Zenyx-Engine/Zenyx/issues
|
|||
We take privacy seriously, and do not perform any automated error collection. In order to improve the software, we rely on people to submit reports.
|
||||
|
||||
Thank you kindly!", log_path.display());
|
||||
println!("{}", panic_msg.red().bold());
|
||||
println!("\nFor future reference, the error summary is as follows:\n{}", payload_str.red().bold());
|
||||
std::process::exit(0);
|
||||
}));
|
||||
});
|
||||
println!("{}", panic_msg.red().bold());
|
||||
println!(
|
||||
"\nFor future reference, the error summary is as follows:\n{}",
|
||||
payload_str.red().bold()
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn render_backtrace() -> String {
|
||||
|
@ -130,7 +125,7 @@ trait Sanitize {
|
|||
impl Sanitize for str {
|
||||
fn sanitize_path(&self) -> String {
|
||||
let username_pattern = r"(?i)(/home/|/Users/|\\Users\\)([^/\\]+)";
|
||||
let re = Regex::new(username_pattern).expect("Failed to sanitize path, aborting operation");
|
||||
let re = Regex::new(username_pattern).expect("Failed to compile regex for sanitization");
|
||||
re.replace_all(self, "${1}<USER>").to_string()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue