diff --git a/src/lib.rs b/src/lib.rs index bc70e69..90c7f53 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,6 +42,7 @@ #![cfg_attr(feature = "nightly", deny(missing_docs))] #![cfg_attr(feature = "nightly", feature(external_doc))] +#![cfg_attr(feature = "nightly", feature(panic_info_message))] extern crate backtrace; #[macro_use] @@ -179,6 +180,15 @@ 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(), + }; + + #[cfg(not(feature = "nightly"))] + let cause = + String::from("Error cause could not be determined by the application."); let payload = panic_info.payload().downcast_ref::<&str>(); if let Some(payload) = payload { @@ -194,7 +204,8 @@ pub fn handle_dump(meta: &Metadata, panic_info: &PanicInfo) -> Option { None => expl.push_str("Panic location unknown.\n"), } - let report = Report::new(&meta.name, &meta.version, Method::Panic, expl); + let report = + Report::new(&meta.name, &meta.version, Method::Panic, expl, cause); match report.persist() { Ok(f) => Some(f), diff --git a/src/report.rs b/src/report.rs index e6b1726..4e28e46 100644 --- a/src/report.rs +++ b/src/report.rs @@ -23,6 +23,7 @@ pub struct Report { operating_system: Cow<'static, str>, crate_version: String, explanation: String, + cause: String, method: Method, backtrace: String, } @@ -34,6 +35,7 @@ impl Report { version: &str, method: Method, explanation: String, + cause: String, ) -> Self { let operating_system = if cfg!(windows) { "windows".into() @@ -50,6 +52,7 @@ impl Report { operating_system, method, explanation, + cause, backtrace, } }