rust-cli / human-panic

Panic messages for humans.
https://docs.rs/human-panic
Apache License 2.0
1.66k stars 65 forks source link

Metadata for error message not parsed properly #2

Closed spacekookie closed 6 years ago

spacekookie commented 6 years ago

So...there seems to be a problem with reading the metdata for the error message.

let _version = env!("CARGO_PKG_VERSION");
let name = env!("CARGO_PKG_NAME");
let authors = env!("CARGO_PKG_AUTHORS");
let homepage = env!("CARGO_PKG_HOMEPAGE");

When using human-panic, in my CLI it still includes the information to your crate:

spacekookie@azedes ~/P/poke> target/debug/poke
Well, this is embarrasing.

human-panic had a problem and crashed. To help us diagnose the problem you can send us a crash report.

We have generated a report file at "<reports not generated yet>". Submit an issue or email with the subject of "human-panic Crash Report" and include the report as an attachment.

- Homepage: https://github.com/yoshuawuyts/human-panic
- Authors: Yoshua Wuyts <yoshuawuyts@gmail.com>

We take privacy seriously, and do not perform any automated error collection. In order to improve the software, we rely on people to submit reports.

Thank you kindly!

I assume I'm using the crate correctly? This is my main:

fn main() {
    human_panic::catch_unwind(|| {
        panic!("something went wrong");
    });
}

In general it's not obvious how to use this? Because the panic text I provide is for example completely ignored. And isn't there a way to generically catch panic! calls?

Edit: Looking at the code, it looks like #1 will fix this? :sweat_smile: I didn't check there was a PR before opening the issue

killercup commented 6 years ago

I don't think #1 will fix this: The problem is that cargo sets these env vars for the crate that is currently being built (which is human-panic).

A solution to this would be to rewrite human_panic::catch_unwind as a macro, so the env! calls are being injected into the main binary code and thus evaluated with its env vars.

spacekookie commented 6 years ago

This was fixed by #5