diff --git a/src/lib.rs b/src/lib.rs index 17adb7a..c8debfd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -199,20 +199,24 @@ pub fn print_msg>( /// Utility function which will handle dumping information to disk pub fn handle_dump(meta: &Metadata, panic_info: &PanicInfo) -> Option { let mut expl = String::new(); + #[cfg(feature = "nightly")] - let cause = match panic_info.message() { - Some(m) => format!("{}", m), - None => "Unknown".into(), - }; + let message = panic_info.message().map(|m| format!("{}", m)); #[cfg(not(feature = "nightly"))] - let cause = - String::from("Error cause could not be determined by the application."); + let message = match ( + panic_info.payload().downcast_ref::<&str>(), + panic_info.payload().downcast_ref::(), + ) { + (Some(s), _) => Some(s.to_string()), + (_, Some(s)) => Some(s.to_string()), + (None, None) => None, + }; - let payload = panic_info.payload().downcast_ref::<&str>(); - if let Some(payload) = payload { - expl.push_str(&format!("Cause: {}. ", &payload)); - } + let cause = match message { + Some(m) => m, + None => "Unknown".into(), + }; match panic_info.location() { Some(location) => expl.push_str(&format!(