Explain backtrace env variable combinations
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Tolnay · committed by David Tolnay · parent c01ceaf · Browse files · 3 files·+31 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+31 added−6 removed
- other:+31 added−6 removed
Provenance
- Commit
4bebd2a- Tree
b548ef0- Author
David Tolnay <dtolnay@gmail.com>- Committer
David Tolnay <dtolnay@gmail.com>- Parent
c01ceaf
3 files changed+31 added−6 removed
modified:src/error.rs+10 added-2 removed
288 unmodified lines289 ///290 /// Backtraces are only available on the nightly channel. Tracking issue:291 /// [rust-lang/rust#53487][tracking].292 ///293- /// In order for the backtrace to be meaningful, the environment variable294- /// `RUST_LIB_BACKTRACE=1` must be defined. Backtraces are somewhat293+ /// In order for the backtrace to be meaningful, one of the two environment294+ /// variables `RUST_LIB_BACKTRACE=1` or `RUST_BACKTRACE=1` must be defined295+ /// and `RUST_LIB_BACKTRACE` must not be `0`. Backtraces are somewhat296 /// expensive to capture in Rust, so we don't necessarily want to be297 /// capturing them all over the place all the time.298 ///299+ /// - If you want panics and errors to both have backtraces, set300+ /// `RUST_BACKTRACE=1`;301+ /// - If you want only errors to have backtraces, set302+ /// `RUST_LIB_BACKTRACE=1`;303+ /// - If you want only panics to have backtraces, set `RUST_BACKTRACE=1` and304+ /// `RUST_LIB_BACKTRACE=0`.305+ ///306 /// [tracking]: https://github.com/rust-lang/rust/issues/53487307 #[cfg(backtrace)]308 pub fn backtrace(&self) -> &Backtrace {309 self.inner.backtrace()492 unmodified linesmodified:src/lib.rs+11 added-2 removed
119 unmodified lines120 //! # ;121 //! ```122 //!123 //! - A backtrace is captured and printed with the error if the underlying error124-//! type does not already provide its own. In order to see backtraces, the125-//! `RUST_LIB_BACKTRACE=1` environment variable must be defined.124+//! type does not already provide its own. In order to see backtraces, they125+//! must be enabled through the environment variables described in126+//! [`std::backtrace`]:127 //!128+//! - If you want panics and errors to both have backtraces, set129+//! `RUST_BACKTRACE=1`;130+//! - If you want only errors to have backtraces, set `RUST_LIB_BACKTRACE=1`;131+//! - If you want only panics to have backtraces, set `RUST_BACKTRACE=1` and132+//! `RUST_LIB_BACKTRACE=0`.133+//!134+//! [`std::backtrace`]: https://doc.rust-lang.org/std/backtrace/index.html#environment-variables135+//!136 //! - Anyhow works with any error type that has an impl of `std::error::Error`,137 //! including ones defined in your crate. We do not bundle a `derive(Error)`138 //! macro but you can write the impls yourself or use a standalone macro like139 //! [thiserror].452 unmodified linesmodified:README.md+10 added-2 removed
73 unmodified lines74757677787978798081828384858687888990919279 unmodified lines73 unmodified lines } ```
- A backtrace is captured and printed with the error if the underlying error type does not already provide its own. In order to see backtraces, the `RUST_LIB_BACKTRACE=1` environment variable must be defined. type does not already provide its own. In order to see backtraces, they must be enabled through the environment variables described in [`std::backtrace`]:
- If you want panics and errors to both have backtraces, set `RUST_BACKTRACE=1`; - If you want only errors to have backtraces, set `RUST_LIB_BACKTRACE=1`; - If you want only panics to have backtraces, set `RUST_BACKTRACE=1` and `RUST_LIB_BACKTRACE=0`.
[`std::backtrace`]: https://doc.rust-lang.org/std/backtrace/index.html#environment-variables
- Anyhow works with any error type that has an impl of `std::error::Error`, including ones defined in your crate. We do not bundle a `derive(Error)` macro but you can write the impls yourself or use a standalone macro like [thiserror].79 unmodified lines