diff --git a/README.md b/README.md index fc764c4..327d317 100644 --- a/README.md +++ b/README.md @@ -49,44 +49,50 @@ Thank you kindly! The error dump file generated by `human-panic` contains the following fields. ```toml -name = 'single-panic-test' -operating_system = 'unix:Unknown' +name = 'single-panic-test2' +operating_system = 'Debian (11) (64-bit)' crate_version = '0.1.0' explanation = ''' -Cause: OMG EVERYTHING IS ON FIRE!!!. Panic occurred in file 'tests/single-panic/src/main.rs' at line 8 +Panic occurred in file 'src/main.rs' at line 7 ''' +cause = 'OMG EVERYTHING IS ON FIRE!!!' method = 'Panic' backtrace = ''' -stack backtrace: - 0: 0x55fa0ed4c1b4 - backtrace::backtrace::libunwind::trace::h69e50feca54bfb84 - at /home/spacekookie/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.6/src/backtrace/libunwind.rs:53 - - backtrace::backtrace::trace::h42967341e0b01ccc - at /home/spacekookie/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.6/src/backtrace/mod.rs:42 - - # ... - - 8: 0x55fa0ebaac8d - single_panic_test::main::h56a3d326bcecfc36 - at tests/single-panic/src/main.rs:8 - 9: 0x55fa0ebaae91 - std::rt::lang_start::{{closure}}::h09d28d8540038bf8 - at /checkout/src/libstd/rt.rs:74 - 10: 0x55fa0ed732f7 - std::rt::lang_start_internal::{{closure}}::h2e4baf0a27c956a3 - at libstd/rt.rs:59 - - std::panicking::try::do_call::h73f98ed0647c7274 - at libstd/panicking.rs:305 - 11: 0x55fa0ed8551e - __rust_maybe_catch_panic - at libpanic_unwind/lib.rs:101 - 12: 0x55fa0ed6f7f5 - std::panicking::try::h18fbb145180d4cd9 - at libstd/panicking.rs:284 - - std::panic::catch_unwind::hc4b6a212a30b4bc5 - at libstd/panic.rs:361 - - std::rt::lang_start_internal::h8b001b4244930d51 - at libstd/rt.rs:58 - 13: 0x55fa0ebaae71 - std::rt::lang_start::h1b1de624209f414a - at /checkout/src/libstd/rt.rs:74 - 14: 0x55fa0ebaacbd - main - 15: 0x7f9946132f29 - __libc_start_main - 16: 0x55fa0eba9b79 - _start - 17: 0x0 - ''' + + 0: 0x55f1b1ed42af - single_panic_test2::main::h71eb4bc2300956b7 + 1: 0x55f1b1ed3623 - std::sys_common::backtrace::__rust_begin_short_backtrace::hb897a2290e3a3ed8 + 2: 0x55f1b1ed35f9 - std::rt::lang_start::{{closure}}::h4a4f0688fcbbe2a8 + 3: 0x55f1b1f1cf3a - core::ops::function::impls:: for &F>::call_once::h02e5de65baee3e0a + at /rustc/d394408fb38c4de61f765a3ed5189d2731a1da91/library/core/src/ops/function.rs:280 + - std::panicking::try::do_call::h928f62916d7b4bf7 + at /rustc/d394408fb38c4de61f765a3ed5189d2731a1da91/library/std/src/panicking.rs:492 + - std::panicking::try::he5e8d9bda1fee0d9 + at /rustc/d394408fb38c4de61f765a3ed5189d2731a1da91/library/std/src/panicking.rs:456 + - std::panic::catch_unwind::hbdacb0480f3c3a44 + at /rustc/d394408fb38c4de61f765a3ed5189d2731a1da91/library/std/src/panic.rs:137 + - std::rt::lang_start_internal::{{closure}}::h9307a76627b54f4f + at /rustc/d394408fb38c4de61f765a3ed5189d2731a1da91/library/std/src/rt.rs:128 + - std::panicking::try::do_call::h0baecbe86a821dd2 + at /rustc/d394408fb38c4de61f765a3ed5189d2731a1da91/library/std/src/panicking.rs:492 + - std::panicking::try::h6c0869befc863f62 + at /rustc/d394408fb38c4de61f765a3ed5189d2731a1da91/library/std/src/panicking.rs:456 + - std::panic::catch_unwind::h135074234245f66c + at /rustc/d394408fb38c4de61f765a3ed5189d2731a1da91/library/std/src/panic.rs:137 + - std::rt::lang_start_internal::h498f9556b87c8e5f + at /rustc/d394408fb38c4de61f765a3ed5189d2731a1da91/library/std/src/rt.rs:128 + 4: 0x55f1b1ed4ed2 - main + 5: 0x7feeb3c40d0a - __libc_start_main + at ./csu/../csu/libc-start.c:308 + 6: 0x55f1b1ed1b3a - _start + 7: 0x0 - ''' +rustc_version = ''' +rustc 1.65.0-nightly (d394408fb 2022-08-07) +binary: rustc +commit-hash: d394408fb38c4de61f765a3ed5189d2731a1da91 +commit-date: 2022-08-07 +host: x86_64-unknown-linux-gnu +release: 1.65.0-nightly +LLVM version: 14.0.6''' ``` ## Usage diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..ab7d3cd --- /dev/null +++ b/build.rs @@ -0,0 +1,21 @@ +use std::process::{Command, Stdio}; + +fn main() { + let mut version = String::new(); + // Cargo passes rustc's binary path as the environment variable RUSTC + let rustc_path = std::env::var("RUSTC").unwrap(); + let command = Command::new(rustc_path) + .arg("-vV") + .stdout(Stdio::piped()) + .spawn(); + if let Ok(command) = command { + let output = command.wait_with_output(); + if let Ok(output) = output { + version = String::from_utf8_lossy(&output.stdout) + .trim() + .replace("\n", "\\n") + .to_string(); + } + } + println!("cargo:rustc-env=RUSTC_VERSION={}", version); +} diff --git a/src/report.rs b/src/report.rs index 28cc0f6..f31cba8 100644 --- a/src/report.rs +++ b/src/report.rs @@ -31,6 +31,7 @@ pub struct Report { cause: String, method: Method, backtrace: String, + rustc_version: String } impl Report { @@ -42,6 +43,7 @@ impl Report { explanation: String, cause: String, ) -> Self { + let rustc_version = env!("RUSTC_VERSION").to_string().replace("\\n", "\n"); let operating_system = os_info::get().to_string(); //We skip 3 frames from backtrace library @@ -114,6 +116,7 @@ impl Report { explanation, cause, backtrace, + rustc_version } }