Skip to content

Commit

Permalink
Including original-sin (panic) in report (#43)
Browse files Browse the repository at this point in the history
Include original panic-cause in report

Further documented in #43 

* Fixing the build on stable through a not-so-nice `cfg` attr
* Fixing broken doc comments
* Outputting a more helpful message when no original-panic could be determined
* Fixing weird artefacts in random locations
* Making rustfmt happy
  • Loading branch information
spacekookie committed Oct 4, 2018
1 parent 8002a42 commit 920251c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/lib.rs
Expand Up @@ -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]
Expand Down Expand Up @@ -179,6 +180,15 @@ 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(),
};

#[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 {
Expand All @@ -194,7 +204,8 @@ pub fn handle_dump(meta: &Metadata, panic_info: &PanicInfo) -> Option<PathBuf> {
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),
Expand Down
3 changes: 3 additions & 0 deletions src/report.rs
Expand Up @@ -23,6 +23,7 @@ pub struct Report {
operating_system: Cow<'static, str>,
crate_version: String,
explanation: String,
cause: String,
method: Method,
backtrace: String,
}
Expand All @@ -34,6 +35,7 @@ impl Report {
version: &str,
method: Method,
explanation: String,
cause: String,
) -> Self {
let operating_system = if cfg!(windows) {
"windows".into()
Expand All @@ -50,6 +52,7 @@ impl Report {
operating_system,
method,
explanation,
cause,
backtrace,
}
}
Expand Down

0 comments on commit 920251c

Please sign in to comment.