From b0056abee122a2372891ae26e54c0063b98bd8ad Mon Sep 17 00:00:00 2001 From: TheTechRobo <52163910+TheTechRobo@users.noreply.github.com> Date: Thu, 18 Aug 2022 14:38:07 -0400 Subject: [PATCH 1/6] Determine Rust version and add it to the report --- build.rs | 20 ++++++++++++++++++++ src/report.rs | 3 +++ 2 files changed, 23 insertions(+) create mode 100644 build.rs diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..021968a --- /dev/null +++ b/build.rs @@ -0,0 +1,20 @@ +use std::process::{Command, Stdio}; + +fn main() { + let mut version = String::new(); + // Cargo passes its binary path as the environment variable CARGO. + let cargo_path = env!("CARGO"); + let command = Command::new(cargo_path) + .arg("version") + .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() + .to_string(); + } + } + println!("cargo:rustc-env=CARGO_VERSION={}", version); +} diff --git a/src/report.rs b/src/report.rs index 28cc0f6..c4d8c3a 100644 --- a/src/report.rs +++ b/src/report.rs @@ -31,6 +31,7 @@ pub struct Report { cause: String, method: Method, backtrace: String, + cargo_version: String } impl Report { @@ -42,6 +43,7 @@ impl Report { explanation: String, cause: String, ) -> Self { + let cargo_version = env!("CARGO_VERSION").to_string(); let operating_system = os_info::get().to_string(); //We skip 3 frames from backtrace library @@ -114,6 +116,7 @@ impl Report { explanation, cause, backtrace, + cargo_version } } From aa66aecb0c8d1627f79ad1f6167596197ec4717b Mon Sep 17 00:00:00 2001 From: TheTechRobo <52163910+TheTechRobo@users.noreply.github.com> Date: Thu, 18 Aug 2022 14:58:47 -0400 Subject: [PATCH 2/6] Update README.md --- README.md | 63 +++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index fc764c4..9c209ed 100644 --- a/README.md +++ b/README.md @@ -50,43 +50,42 @@ The error dump file generated by `human-panic` contains the following fields. ```toml name = 'single-panic-test' -operating_system = 'unix:Unknown' +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: 0x5653024632af - single_panic_test::main::he5bb913b8d0d66af + 1: 0x565302462623 - std::sys_common::backtrace::__rust_begin_short_backtrace::hd30268eb783a3896 + 2: 0x5653024625f9 - std::rt::lang_start::{{closure}}::h13e747e3f66b7484 + 3: 0x5653024ab7da - 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: 0x565302463ed2 - main + 5: 0x7f0d6200cd0a - __libc_start_main + at ./csu/../csu/libc-start.c:308 + 6: 0x565302460b3a - _start + 7: 0x0 - ''' +cargo_version = 'cargo 1.65.0-nightly (4fd148c47 2022-08-03)' ``` ## Usage From f553a4574819b7002dc04459a055752e6b621897 Mon Sep 17 00:00:00 2001 From: TheTechRobo <52163910+TheTechRobo@users.noreply.github.com> Date: Thu, 18 Aug 2022 15:07:27 -0400 Subject: [PATCH 3/6] Use cargo -vV rather than cargo version --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 021968a..231ff91 100644 --- a/build.rs +++ b/build.rs @@ -5,7 +5,7 @@ fn main() { // Cargo passes its binary path as the environment variable CARGO. let cargo_path = env!("CARGO"); let command = Command::new(cargo_path) - .arg("version") + .arg("-vV") .stdout(Stdio::piped()) .spawn(); if let Ok(command) = command { From 70f509e14cf5089ee2fd744960eaecf0fb51b576 Mon Sep 17 00:00:00 2001 From: TheTechRobo <52163910+TheTechRobo@users.noreply.github.com> Date: Thu, 18 Aug 2022 15:13:45 -0400 Subject: [PATCH 4/6] Actually capture all the Cargo version data --- build.rs | 1 + src/report.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index 231ff91..5f9d816 100644 --- a/build.rs +++ b/build.rs @@ -13,6 +13,7 @@ fn main() { if let Ok(output) = output { version = String::from_utf8_lossy(&output.stdout) .trim() + .replace("\n", "\\n") .to_string(); } } diff --git a/src/report.rs b/src/report.rs index c4d8c3a..d409b53 100644 --- a/src/report.rs +++ b/src/report.rs @@ -43,7 +43,7 @@ impl Report { explanation: String, cause: String, ) -> Self { - let cargo_version = env!("CARGO_VERSION").to_string(); + let cargo_version = env!("CARGO_VERSION").to_string().replace("\\n", "\n"); let operating_system = os_info::get().to_string(); //We skip 3 frames from backtrace library From 532b7acbe98accabcd37c96ac2d80883cfb60767 Mon Sep 17 00:00:00 2001 From: TheTechRobo <52163910+TheTechRobo@users.noreply.github.com> Date: Thu, 18 Aug 2022 15:19:16 -0400 Subject: [PATCH 5/6] Check rustc's version rather than Cargo's --- build.rs | 8 ++++---- src/report.rs | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/build.rs b/build.rs index 5f9d816..ab7d3cd 100644 --- a/build.rs +++ b/build.rs @@ -2,9 +2,9 @@ use std::process::{Command, Stdio}; fn main() { let mut version = String::new(); - // Cargo passes its binary path as the environment variable CARGO. - let cargo_path = env!("CARGO"); - let command = Command::new(cargo_path) + // 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(); @@ -17,5 +17,5 @@ fn main() { .to_string(); } } - println!("cargo:rustc-env=CARGO_VERSION={}", version); + println!("cargo:rustc-env=RUSTC_VERSION={}", version); } diff --git a/src/report.rs b/src/report.rs index d409b53..f31cba8 100644 --- a/src/report.rs +++ b/src/report.rs @@ -31,7 +31,7 @@ pub struct Report { cause: String, method: Method, backtrace: String, - cargo_version: String + rustc_version: String } impl Report { @@ -43,7 +43,7 @@ impl Report { explanation: String, cause: String, ) -> Self { - let cargo_version = env!("CARGO_VERSION").to_string().replace("\\n", "\n"); + 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 @@ -116,7 +116,7 @@ impl Report { explanation, cause, backtrace, - cargo_version + rustc_version } } From 407cc8437ecd292241672ea358baa21037166121 Mon Sep 17 00:00:00 2001 From: TheTechRobo <52163910+TheTechRobo@users.noreply.github.com> Date: Thu, 18 Aug 2022 15:24:44 -0400 Subject: [PATCH 6/6] Address review comment in docs --- README.md | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 9c209ed..327d317 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Thank you kindly! The error dump file generated by `human-panic` contains the following fields. ```toml -name = 'single-panic-test' +name = 'single-panic-test2' operating_system = 'Debian (11) (64-bit)' crate_version = '0.1.0' explanation = ''' @@ -59,10 +59,10 @@ cause = 'OMG EVERYTHING IS ON FIRE!!!' method = 'Panic' backtrace = ''' - 0: 0x5653024632af - single_panic_test::main::he5bb913b8d0d66af - 1: 0x565302462623 - std::sys_common::backtrace::__rust_begin_short_backtrace::hd30268eb783a3896 - 2: 0x5653024625f9 - std::rt::lang_start::{{closure}}::h13e747e3f66b7484 - 3: 0x5653024ab7da - core::ops::function::impls:: for &F>::call_once::h02e5de65baee3e0a + 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 @@ -80,12 +80,19 @@ backtrace = ''' 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: 0x565302463ed2 - main - 5: 0x7f0d6200cd0a - __libc_start_main + 4: 0x55f1b1ed4ed2 - main + 5: 0x7feeb3c40d0a - __libc_start_main at ./csu/../csu/libc-start.c:308 - 6: 0x565302460b3a - _start + 6: 0x55f1b1ed1b3a - _start 7: 0x0 - ''' -cargo_version = 'cargo 1.65.0-nightly (4fd148c47 2022-08-03)' +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