-
Notifications
You must be signed in to change notification settings - Fork 61
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
Please make "backtraces" feature opt-in, not opt-out #113
Comments
But the consumer is not actually in charge of this. The library creating the error already has to add a #[derive(Snafu)]
enum Error {
Something { backtrace: Backtrace }
} With your proposed end result, every crate will also need to
These multiple steps make me worried that library authors simply won't use backtraces at all, negating any benefits. There's an inherent tension around default features. Without a feature by default, people get confused because "the docs show it's there, but it doesn't work for me". With a feature by default, time and space can be wasted on unused functionality. Additionally, there's tension between library usage and application usage. Libraries should strive to be minimal in what they bring in to better work in more contexts, but applications tend to want to be maximal. Anecdotally, library crates do a poor job of using
Can you provide some concrete cases where such a thing would be beneficial? Presumably you are encountering one "in the wild" to prompt the request. |
I wonder if we could do something like #[cfg(backtrace)]
struct Backtrace(...);
#[cfg(not(backtrace))]
struct Backtrace; This would lift the need for each library to add the conditional compilation. It might also allow them to avoid adding a feature flag, as the application author could be responsible for adding |
Another point is that eventually, backtraces will be added to the standard library. This will essentially make it "free" to use a backtrace. |
Thanks for the very quick feedback! I don't have a direct report from the field, as I'm still in the planning phase of migrating my existing crates (e.g. I maintain a mix of both libraries and applications. For the former, it is painful to keep tracking and disabling default features, in order to let application developers being in control. For the latter, opt-ing out default features through chained dependencies becomes a game of whack-a-mole. You suggestion of an inert |
General plan:
For a library author, they just scatter An application author adds |
I didn't see opposition to this and the plan above seemed well-rounded, so I proceeded and opened a PR at #157. |
Since #12
snafu
supports capturing backtraces. While useful in several contexts, backtraces comes with additional costs both at runtime (#84) and at buildtime (it usesbacktrace-sys
under the hood, which brings in C source/compilation).Backtraces are currently active by default and needs to be disabled (opt-out) by consumers via the
default-features = false
syntax.In the context of an ecosystem of snafu-using libraries, this poses a problem when nesting a couple of levels of dependencies, as the top-level consumer is no more in charge of those features and can't directly opt-out.
Considering that cargo features are additive, a better approach would be to make backtraces disabled by default and let the final consumer enable them via a dedicated feature (opt-in).
That way any intermediate library could re-export the
snafu/backtraces
feature, and the top-level application/consumer would be the one (optionally) in charge of enabling backtraces across all crates.The text was updated successfully, but these errors were encountered: