From 7b0af42812b2e5d17004110688e8fc796ba6eff2 Mon Sep 17 00:00:00 2001 From: Leonhard Markert Date: Fri, 15 Nov 2019 17:03:25 +0100 Subject: [PATCH 1/2] Include cause, whether on nightly or not --- src/lib.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 17adb7a..9a92d09 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -200,19 +200,15 @@ pub fn print_msg>( 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(); #[cfg(not(feature = "nightly"))] - let cause = - String::from("Error cause could not be determined by the application."); + let message = panic_info.payload().downcast_ref::<&str>(); - 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) => format!("{}", m), + None => "Unknown".into(), + }; match panic_info.location() { Some(location) => expl.push_str(&format!( From c45e10c76a31673a1e3c15b3ad10709030c8dc49 Mon Sep 17 00:00:00 2001 From: Leonhard Markert Date: Fri, 15 Nov 2019 18:29:09 +0100 Subject: [PATCH 2/2] Try downcasting from &str and String --- src/lib.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9a92d09..c8debfd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -199,14 +199,22 @@ 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 message = panic_info.message(); + let message = panic_info.message().map(|m| format!("{}", m)); #[cfg(not(feature = "nightly"))] - let message = panic_info.payload().downcast_ref::<&str>(); + 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 cause = match message { - Some(m) => format!("{}", m), + Some(m) => m, None => "Unknown".into(), };