mirror of
https://github.com/eyre-rs/eyre.git
synced 2025-09-29 22:11:55 +00:00
merge upstream changes from anyhow (#10)
This commit is contained in:
parent
e3bf56ef5c
commit
3ac0be8322
@ -15,10 +15,14 @@ default = ["std"]
|
|||||||
std = []
|
std = []
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
futures = "0.3"
|
futures = { version = "0.3", default-features = false }
|
||||||
rustversion = "1.0"
|
rustversion = "1.0"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
trybuild = { version = "1.0.19", features = ["diff"] }
|
trybuild = { version = "1.0.19", features = ["diff"] }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
indenter = "^0.1.1"
|
indenter = "^0.1.1"
|
||||||
|
|
||||||
|
[package.metadata.docs.rs]
|
||||||
|
targets = ["x86_64-unknown-linux-gnu"]
|
||||||
|
rustdoc-args = ["--cfg", "doc_cfg"]
|
||||||
|
18
README.md
18
README.md
@ -199,9 +199,21 @@ type Result<T, E = eyre::Report<MyContext>> = core::result::Result<T, E>;
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
- A backtrace is captured and printed with the error if the underlying error
|
- If using the nightly channel, a backtrace is captured and printed with the
|
||||||
type does not already provide its own. In order to see backtraces, the
|
error if the underlying error type does not already provide its own. In order
|
||||||
`RUST_LIB_BACKTRACE=1` environment variable must be defined.
|
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`.
|
||||||
|
|
||||||
|
The tracking issue for this feature is [rust-lang/rust#53487].
|
||||||
|
|
||||||
|
[`std::backtrace`]: https://doc.rust-lang.org/std/backtrace/index.html#environment-variables
|
||||||
|
[rust-lang/rust#53487]: https://github.com/rust-lang/rust/issues/53487
|
||||||
|
|
||||||
- Eyre works with any error type that has an impl of `std::error::Error`,
|
- Eyre 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
|
including ones defined in your crate. We do not bundle a `derive(Error)` macro
|
||||||
|
13
src/error.rs
13
src/error.rs
@ -26,6 +26,7 @@ where
|
|||||||
/// If the error type does not provide a backtrace, a backtrace will be
|
/// If the error type does not provide a backtrace, a backtrace will be
|
||||||
/// created here to ensure that a backtrace exists.
|
/// created here to ensure that a backtrace exists.
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
|
#[cfg_attr(doc_cfg, doc(cfg(feature = "std")))]
|
||||||
pub fn new<E>(error: E) -> Self
|
pub fn new<E>(error: E) -> Self
|
||||||
where
|
where
|
||||||
E: StdError + Send + Sync + 'static,
|
E: StdError + Send + Sync + 'static,
|
||||||
@ -266,11 +267,19 @@ where
|
|||||||
/// Backtraces are only available on the nightly channel. Tracking issue:
|
/// Backtraces are only available on the nightly channel. Tracking issue:
|
||||||
/// [rust-lang/rust#53487][tracking].
|
/// [rust-lang/rust#53487][tracking].
|
||||||
///
|
///
|
||||||
/// In order for the backtrace to be meaningful, the environment variable
|
/// In order for the backtrace to be meaningful, one of the two environment
|
||||||
/// `RUST_LIB_BACKTRACE=1` must be defined. Backtraces are somewhat
|
/// variables `RUST_LIB_BACKTRACE=1` or `RUST_BACKTRACE=1` must be defined
|
||||||
|
/// and `RUST_LIB_BACKTRACE` must not be `0`. Backtraces are somewhat
|
||||||
/// expensive to capture in Rust, so we don't necessarily want to be
|
/// expensive to capture in Rust, so we don't necessarily want to be
|
||||||
/// capturing them all over the place all the time.
|
/// capturing them all over the place all the time.
|
||||||
///
|
///
|
||||||
|
/// - 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`.
|
||||||
|
///
|
||||||
/// [tracking]: https://github.com/rust-lang/rust/issues/53487
|
/// [tracking]: https://github.com/rust-lang/rust/issues/53487
|
||||||
#[cfg(backtrace)]
|
#[cfg(backtrace)]
|
||||||
pub fn backtrace(&self) -> &Backtrace {
|
pub fn backtrace(&self) -> &Backtrace {
|
||||||
|
19
src/lib.rs
19
src/lib.rs
@ -250,9 +250,21 @@
|
|||||||
//! # ;
|
//! # ;
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//! - A backtrace is captured and printed with the error if the underlying error
|
//! - If using the nightly channel, a backtrace is captured and printed with the
|
||||||
//! type does not already provide its own. In order to see backtraces, the
|
//! error if the underlying error type does not already provide its own. In
|
||||||
//! `RUST_LIB_BACKTRACE=1` environment variable must be defined.
|
//! 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`.
|
||||||
|
//!
|
||||||
|
//! The tracking issue for this feature is [rust-lang/rust#53487].
|
||||||
|
//!
|
||||||
|
//! [`std::backtrace`]: https://doc.rust-lang.org/std/backtrace/index.html#environment-variables
|
||||||
|
//! [rust-lang/rust#53487]: https://github.com/rust-lang/rust/issues/53487
|
||||||
//!
|
//!
|
||||||
//! - Eyre works with any error type that has an impl of `std::error::Error`,
|
//! - Eyre 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)`
|
//! including ones defined in your crate. We do not bundle a `derive(Error)`
|
||||||
@ -316,6 +328,7 @@
|
|||||||
|
|
||||||
#![doc(html_root_url = "https://docs.rs/eyre/0.3.8")]
|
#![doc(html_root_url = "https://docs.rs/eyre/0.3.8")]
|
||||||
#![cfg_attr(backtrace, feature(backtrace))]
|
#![cfg_attr(backtrace, feature(backtrace))]
|
||||||
|
#![cfg_attr(doc_cfg, feature(doc_cfg))]
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
#![allow(
|
#![allow(
|
||||||
clippy::needless_doctest_main,
|
clippy::needless_doctest_main,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user