diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 85bacd1..2537d4e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,7 +64,7 @@ jobs: - uses: actions/checkout@v1 - uses: actions-rs/toolchain@v1 with: - toolchain: 1.39 + toolchain: 1.42 override: true - uses: actions-rs/cargo@v1 with: diff --git a/.gitignore b/.gitignore index 6936990..751767d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target **/*.rs.bk Cargo.lock +/.pijul/ diff --git a/CHANGELOG.md b/CHANGELOG.md index 904a170..16c3f1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ReleaseDate +## [0.6.5] - 2021-01-05 +### Added +- add optional support for converting into `pyo3` exceptions + ## [0.6.4] - 2021-01-04 ### Fixed - added missing track_caller annotations to `wrap_err` related trait methods @@ -26,7 +30,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 -[Unreleased]: https://github.com/yaahc/eyre/compare/v0.6.4...HEAD +[Unreleased]: https://github.com/yaahc/eyre/compare/v0.6.5...HEAD +[0.6.5]: https://github.com/yaahc/eyre/compare/v0.6.4...v0.6.5 [0.6.4]: https://github.com/yaahc/eyre/compare/v0.6.3...v0.6.4 [0.6.3]: https://github.com/yaahc/eyre/compare/v0.6.2...v0.6.3 [0.6.2]: https://github.com/yaahc/eyre/compare/v0.6.1...v0.6.2 diff --git a/Cargo.toml b/Cargo.toml index 196bf40..861172f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "eyre" -version = "0.6.4" +version = "0.6.5" authors = ["David Tolnay ", "Jane Lusby "] edition = "2018" license = "MIT OR Apache-2.0" @@ -21,6 +21,8 @@ thiserror = "1.0" trybuild = { version = "1.0.19", features = ["diff"] } backtrace = "0.3.46" anyhow = "1.0.28" +syn = { version = "1.0", features = ["full"] } +pyo3 = { version = "0.13", default-features = false, features = ["auto-initialize"] } [dependencies] indenter = "0.3.0" diff --git a/examples/custom_handler.rs b/examples/custom_handler.rs index dfc90e1..a6f0ab2 100644 --- a/examples/custom_handler.rs +++ b/examples/custom_handler.rs @@ -62,7 +62,7 @@ impl EyreHandler for Handler { return fmt::Debug::fmt(error, f); } - let errors = iter::successors(Some(error), |error| error.source()); + let errors = iter::successors(Some(error), |error| (*error).source()); for (ind, error) in errors.enumerate() { write!(f, "\n{:>4}: {}", ind, error)?; diff --git a/src/error.rs b/src/error.rs index 20f34ac..5e4fb04 100644 --- a/src/error.rs +++ b/src/error.rs @@ -8,9 +8,6 @@ use core::ptr::{self, NonNull}; use core::ops::{Deref, DerefMut}; -#[cfg(feature = "pyo3")] -mod pyo3_compat; - impl Report { /// Create a new error object from any error type. /// @@ -622,13 +619,12 @@ unsafe fn context_chain_downcast(e: &ErrorImpl<()>, target: TypeId) -> Option where D: 'static, { + let unerased = e as *const ErrorImpl<()> as *const ErrorImpl>; if TypeId::of::() == target { - let unerased = e as *const ErrorImpl<()> as *const ErrorImpl>; let addr = &(*unerased)._object.msg as *const D as *mut (); Some(NonNull::new_unchecked(addr)) } else { // Recurse down the context chain per the inner error's vtable. - let unerased = e as *const ErrorImpl<()> as *const ErrorImpl>; let source = &(*unerased)._object.error; (source.inner.vtable.object_downcast)(&source.inner, target) } @@ -767,3 +763,6 @@ impl AsRef for Report { &**self } } + +#[cfg(feature = "pyo3")] +mod pyo3_compat; diff --git a/src/lib.rs b/src/lib.rs index 8f366dd..24443f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -283,7 +283,7 @@ //! [`simple-eyre`]: https://github.com/yaahc/simple-eyre //! [`color-spantrace`]: https://github.com/yaahc/color-spantrace //! [`color-backtrace`]: https://github.com/athre0z/color-backtrace -#![doc(html_root_url = "https://docs.rs/eyre/0.6.4")] +#![doc(html_root_url = "https://docs.rs/eyre/0.6.5")] #![warn( missing_debug_implementations, missing_docs, @@ -519,7 +519,7 @@ impl StdError for InstallError {} /// return fmt::Debug::fmt(error, f); /// } /// -/// let errors = iter::successors(Some(error), |error| error.source()); +/// let errors = iter::successors(Some(error), |error| (*error).source()); /// /// for (ind, error) in errors.enumerate() { /// write!(f, "\n{:>4}: {}", ind, error)?; diff --git a/src/macros.rs b/src/macros.rs index 8418d55..0a1c81f 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -40,6 +40,7 @@ /// /// # fn main() -> Result<()> { /// # let depth = 0; +/// # let err: &'static dyn std::error::Error = &ScienceError::RecursionLimitExceeded; /// # /// if depth > MAX_DEPTH { /// bail!(ScienceError::RecursionLimitExceeded); diff --git a/tests/ui/no-impl.rs b/tests/ui/no-impl.rs deleted file mode 100644 index 176ba65..0000000 --- a/tests/ui/no-impl.rs +++ /dev/null @@ -1,8 +0,0 @@ -use eyre::eyre; - -#[derive(Debug)] -struct Error; - -fn main() { - let _ = eyre!(Error); -} diff --git a/tests/ui/no-impl.stderr b/tests/ui/no-impl.stderr deleted file mode 100644 index 442db83..0000000 --- a/tests/ui/no-impl.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0599]: no method named `eyre_kind` found for reference `&Error` in the current scope - --> $DIR/no-impl.rs:7:13 - | -4 | struct Error; - | ------------- - | | - | doesn't satisfy `Error: Into` - | doesn't satisfy `Error: eyre::private::kind::TraitKind` - | doesn't satisfy `Error: std::fmt::Display` -... -7 | let _ = eyre!(Error); - | ^^^^^^^^^^^^ method not found in `&Error` - | - = note: the method `eyre_kind` exists but the following trait bounds were not satisfied: - `Error: Into` - which is required by `Error: eyre::private::kind::TraitKind` - `Error: std::fmt::Display` - which is required by `&Error: eyre::private::kind::AdhocKind` - `&Error: Into` - which is required by `&Error: eyre::private::kind::TraitKind` - = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)