Skip to content

Commit

Permalink
Merge pull request #66 from tweag/cause-nightly-or-not
Browse files Browse the repository at this point in the history
Include cause, whether on nightly or not
  • Loading branch information
Dylan-DPC authored Jan 15, 2020
2 parents 70db948 + c45e10c commit 5195002
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,24 @@ pub fn print_msg<P: AsRef<Path>>(
/// Utility function which will handle dumping information to disk
pub fn handle_dump(meta: &Metadata, panic_info: &PanicInfo) -> Option<PathBuf> {
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::<String>(),
) {
(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!(
Expand Down

0 comments on commit 5195002

Please sign in to comment.