diff --git a/src/lib.rs b/src/lib.rs index 361c0e9..6f2eb81 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,8 +13,8 @@ use report::{Method, Report}; use failure::Error as FailError; use std::io::{Result as IoResult, Write}; -use std::path::{Path, PathBuf}; use std::panic::PanicInfo; +use std::path::{Path, PathBuf}; use termcolor::{BufferWriter, Color, ColorChoice, ColorSpec, WriteColor}; /// A convenient metadata struct that describes a crate @@ -45,8 +45,8 @@ macro_rules! setup_panic { }; panic::set_hook(Box::new(move |info: &PanicInfo| { - let file_path = - handle_dump(info).expect("human-panic: dumping logs to disk failed"); + let file_path = handle_dump(&meta, info) + .expect("human-panic: dumping logs to disk failed"); print_msg(&file_path, &meta) .expect("human-panic: printing error message to console failed"); @@ -101,7 +101,10 @@ pub fn print_msg>( } /// Utility function which will handle dumping information to disk -pub fn handle_dump(panic_info: &PanicInfo) -> Result { +pub fn handle_dump( + meta: &Metadata, + panic_info: &PanicInfo, +) -> Result { let mut expl = String::new(); let payload = panic_info.payload().downcast_ref::<&str>(); @@ -118,6 +121,6 @@ pub fn handle_dump(panic_info: &PanicInfo) -> Result { None => expl.push_str("Panic location unknown.\n"), } - let report = Report::new(Method::Panic, expl); + let report = Report::new(&meta.name, &meta.version, Method::Panic, expl); report.persist() } diff --git a/src/report.rs b/src/report.rs index d49db9f..d2ef441 100644 --- a/src/report.rs +++ b/src/report.rs @@ -10,7 +10,7 @@ use self::uuid::Uuid; use std::{env, fs::File, io::Write, path::Path, path::PathBuf}; /// Method of failure. -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, Clone, Copy)] pub enum Method { Panic, } @@ -26,7 +26,12 @@ pub struct Report { impl Report { /// Create a new instance. - pub fn new(method: Method, explanation: String) -> Self { + pub fn new( + name: &str, + version: &str, + method: Method, + explanation: String, + ) -> Self { let operating_system = if cfg!(windows) { "windows".to_string() } else { @@ -35,8 +40,8 @@ impl Report { }; Self { - crate_version: env!("CARGO_PKG_VERSION").to_string(), - name: env!("CARGO_PKG_NAME").to_string(), + crate_version: version.to_string(), + name: name.to_string(), operating_system, method, explanation,