One of my users has reported having this error message: thread panicked while processing panic. aborting.
Even with the same data on the same OS I can't reproduce the bug.
Here's my main():
fn main() {
panic::set_hook(Box::new(|info| {
eprint!(
"Unexpected error: {}",
info.payload().downcast_ref::<&str>().unwrap()
);
if let Some(location) = info.location() {
eprint!(" ({} {})", location.file(), location.line());
}
eprintln!("");
}));
let code = real_main(); // returns an i32
process::exit(code);
}
I thought this would catch all panics and at least cleanly exit, but it seems not. Is it possible to make it catch any panic and at least cleanly exit. Ideally saying why/where it panicked?
This unwrap may be panicing. According to the docs, payload "will commonly, but not always, be a &'static str or String." If it's a String, then your downcast_ref will return None.
To be more precise, if panicked via panic!("Static message") the payload will be a &'static str. If there were format arguments (panic!("{}", something)), the payload will be a String. But it can also be something else.