diff --git a/crates/matrix-sdk/Cargo.toml b/crates/matrix-sdk/Cargo.toml index 4a03b138e..ee8b93c10 100644 --- a/crates/matrix-sdk/Cargo.toml +++ b/crates/matrix-sdk/Cargo.toml @@ -38,6 +38,7 @@ anyhow = { version = "1.0.42", optional = true } bytes = "1.0.1" dashmap = "4.0.2" event-listener = "2.5.1" +eyre = { version = "0.6.5", optional = true } futures = "0.3.15" http = "0.2.4" matrix-sdk-common = { version = "0.4.0", path = "../matrix-sdk-common" } diff --git a/crates/matrix-sdk/README.md b/crates/matrix-sdk/README.md index 3911764d7..bc9c23c3b 100644 --- a/crates/matrix-sdk/README.md +++ b/crates/matrix-sdk/README.md @@ -62,6 +62,8 @@ The following crate feature flags are available: high-level API there's the `matrix-sdk-appservice` crate * `anyhow`: More verbose error logging for event handlers that return `anyhow::Result<()>`. +* `eyre`: More verbose error logging for event handlers that return + `eyre::Result<()>`. # Enabling logging diff --git a/crates/matrix-sdk/src/event_handler.rs b/crates/matrix-sdk/src/event_handler.rs index 4834bd9bd..016030cd3 100644 --- a/crates/matrix-sdk/src/event_handler.rs +++ b/crates/matrix-sdk/src/event_handler.rs @@ -30,7 +30,7 @@ //! //! For more details, see the [`EventHandler`] trait. -#[cfg(feature = "anyhow")] +#[cfg(any(feature = "anyhow", feature = "eyre"))] use std::any::TypeId; use std::{borrow::Cow, fmt, future::Future, ops::Deref}; @@ -70,8 +70,9 @@ pub trait SyncEvent { /// that implements [`SyncEvent`]. Any additional arguments need to implement /// the [`EventHandlerContext`] trait. /// * Their return type has to be one of: `()`, `Result<(), impl Display + Debug -/// + 'static>` (if you are using `anyhow::Result` you can additionally enable -/// the `anyhow` feature to get the verbose `Debug` output printed on error) +/// + 'static>` (if you are using `anyhow::Result` or `eyre::Result` you can +/// additionally enable the `anyhow` / `eyre` feature to get the verbose +/// `Debug` output printed on error) /// /// ### How it works /// @@ -197,6 +198,10 @@ impl EventHandlerResult for Result<(), E Err(e) if TypeId::of::() == TypeId::of::() => { tracing::error!("Event handler for `{}` failed: {:?}", event_type, e); } + #[cfg(feature = "eyre")] + Err(e) if TypeId::of::() == TypeId::of::() => { + tracing::error!("Event handler for `{}` failed: {:?}", event_type, e); + } Err(e) => { tracing::error!("Event handler for `{}` failed: {}", event_type, e); }