hash icon indicating copy to clipboard operation
hash copied to clipboard

GEN-115: Way to disable error location and/or backtrace

Open SUPERCILEX opened this issue 2 years ago • 4 comments

Related Problem

No response

Proposed Solution

It'd be nice to have a cargo feature available to disable location capturing/printing. Example:

Error: File or directory not found: "misclassified.png"
├╴at rmz/src/main.rs:52:17
â•°â•´Use --force to ignore.

For end users, the at rmz/src/main.rs:52:17 is just noise so ideally I'd be able to keep that stuff on in debug mode and feature flag it off in release mode.

Similarly, it'd be nice to completely compile out backtrace support if the backtrace feature isn't enabled in the stdlib: https://doc.rust-lang.org/cargo/reference/unstable.html#build-std-features

Alternatives

No response

Additional context

No response

SUPERCILEX avatar Oct 08 '23 22:10 SUPERCILEX

It's possible to disable the location by setting a custom debug hook for Location:

error_stack::Report::install_debug_hook::<Location>(|_, _| {});

For more information about the debug hooks please see the corresponding documentation.

Related discussion:

  • #1215

I filed a PR to make this feature more visible in the docs.


Backtraces are only shown if you run your program with backtraces enabled, typically this is done by setting RUST_BACKTRACE=1. No backtraces will be shown if none were captured.

TimDiekmann avatar Oct 09 '23 01:10 TimDiekmann

Thanks for the debug hook solution!

For backtraces, I'm asking for support to be compiled out completely. RUST_BACKTRACE=1 won't work with panic_immediate_abort so having it in the binary is a waste.

SUPERCILEX avatar Oct 09 '23 05:10 SUPERCILEX

Hmm, I haven't thought about panic_immediate_abort (and also only used that in very few contexts so far). But as this is typically used in contexts where binary size does in fact matter it's a good suggestion. Is there an easy way to detect certain features or is there a dedicated compile-test required in build.rs?

TimDiekmann avatar Oct 09 '23 11:10 TimDiekmann

I'm not sure unfortunately, though I think the easiest way to go about this is to have a release mode and all modes feature flag (like the log crate) that compiles out support.

SUPERCILEX avatar Oct 09 '23 15:10 SUPERCILEX