Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include cause, whether on nightly or not #66

Merged
merged 2 commits into from
Jan 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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