Browse Source
861: Phase out `log_error` macro r=luckysori a=luckysori Fixes #553. Co-authored-by: Lucas Soriano del Pino <lucas_soriano@fastmail.com>update-blockstream-electrum-server-url
bors[bot]
3 years ago
committed by
GitHub
15 changed files with 267 additions and 165 deletions
@ -1,9 +0,0 @@ |
|||
/// Wrapper for handlers to log errors
|
|||
#[macro_export] |
|||
macro_rules! log_error { |
|||
($future:expr) => { |
|||
if let Err(e) = $future.await { |
|||
tracing::error!("Message handler failed: {:#}", e); |
|||
} |
|||
}; |
|||
} |
@ -0,0 +1,50 @@ |
|||
use async_trait::async_trait; |
|||
use xtra::address; |
|||
use xtra::message_channel; |
|||
use xtra::Actor; |
|||
use xtra::Disconnected; |
|||
use xtra::Message; |
|||
|
|||
#[async_trait] |
|||
pub trait LogFailure { |
|||
async fn log_failure(self, context: &str) -> Result<(), Disconnected>; |
|||
} |
|||
|
|||
#[async_trait] |
|||
impl<A, M> LogFailure for address::SendFuture<A, M> |
|||
where |
|||
A: Actor, |
|||
M: Message<Result = anyhow::Result<()>>, |
|||
{ |
|||
async fn log_failure(self, context: &str) -> Result<(), Disconnected> { |
|||
if let Err(e) = self.await? { |
|||
tracing::warn!( |
|||
"{}: Message handler for message {} failed: {:#}", |
|||
context, |
|||
std::any::type_name::<M>(), |
|||
e |
|||
); |
|||
} |
|||
|
|||
Ok(()) |
|||
} |
|||
} |
|||
|
|||
#[async_trait] |
|||
impl<M> LogFailure for message_channel::SendFuture<M> |
|||
where |
|||
M: xtra::Message<Result = anyhow::Result<()>>, |
|||
{ |
|||
async fn log_failure(self, context: &str) -> Result<(), Disconnected> { |
|||
if let Err(e) = self.await? { |
|||
tracing::warn!( |
|||
"{}: Message handler for message {} failed: {:#}", |
|||
context, |
|||
std::any::type_name::<M>(), |
|||
e |
|||
); |
|||
} |
|||
|
|||
Ok(()) |
|||
} |
|||
} |
Loading…
Reference in new issue