Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SUPERCILEX opened this issue Oct 8, 2023 · 4 comments
Open

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

SUPERCILEX opened this issue Oct 8, 2023 · 4 comments
Assignees
Labels
area/libs > error-stack Affects the `error-stack` crate (library) area/libs Relates to first-party libraries/crates/packages (area) category/enhancement New feature or request hint/help wanted Experience: Extra attention is needed lang/rust Pull requests that update Rust code priority/3 low Lower priority: nice-to-have

Comments

@SUPERCILEX
Copy link

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 SUPERCILEX added the category/enhancement New feature or request label Oct 8, 2023
@TimDiekmann
Copy link
Member

TimDiekmann commented Oct 9, 2023

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:

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 TimDiekmann added the area/libs > error-stack Affects the `error-stack` crate (library) label Oct 9, 2023
@SUPERCILEX
Copy link
Author

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.

@TimDiekmann
Copy link
Member

TimDiekmann commented Oct 9, 2023

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 TimDiekmann reopened this Oct 9, 2023
@TimDiekmann TimDiekmann changed the title Way to disable error location and/or backtrace GEN-115: Way to disable error location and/or backtrace Oct 9, 2023
@SUPERCILEX
Copy link
Author

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.

@vilkinsons vilkinsons added priority/3 low Lower priority: nice-to-have hint/help wanted Experience: Extra attention is needed labels Jan 8, 2024
@vilkinsons vilkinsons added the lang/rust Pull requests that update Rust code label Apr 16, 2024
@vilkinsons vilkinsons added the area/libs Relates to first-party libraries/crates/packages (area) label Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/libs > error-stack Affects the `error-stack` crate (library) area/libs Relates to first-party libraries/crates/packages (area) category/enhancement New feature or request hint/help wanted Experience: Extra attention is needed lang/rust Pull requests that update Rust code priority/3 low Lower priority: nice-to-have
Development

No branches or pull requests

3 participants