diff --git a/mithril-aggregator/src/event_store/transmitter_service.rs b/mithril-aggregator/src/event_store/transmitter_service.rs index bcf21b611b..817e5fd33c 100644 --- a/mithril-aggregator/src/event_store/transmitter_service.rs +++ b/mithril-aggregator/src/event_store/transmitter_service.rs @@ -1,8 +1,9 @@ +use anyhow::Context; use slog::{warn, Logger}; use std::fmt::Debug; use tokio::sync::mpsc::UnboundedSender; -use mithril_common::logging::LoggerExtensions; +use mithril_common::{logging::LoggerExtensions, StdResult}; use super::EventMessage; @@ -36,11 +37,12 @@ where impl TransmitterService { /// Send an [EventMessage]. - pub fn try_send( - &self, - message: EventMessage, - ) -> Result<(), tokio::sync::mpsc::error::SendError> { - self.get_transmitter().send(message) + pub fn try_send(&self, message: EventMessage) -> StdResult<()> { + self.get_transmitter() + .send(message.clone()) + .with_context(|| { + format!("An error occurred when sending message {message:?} to monitoring.") + }) } /// Send an [EventMessage]. @@ -49,9 +51,7 @@ impl TransmitterService { /// If there is one, a warning is issued so the resulting error may be safely ignored by the caller. pub fn send(&self, message: EventMessage) { if let Err(e) = self.try_send(message.clone()) { - let error_msg = - format!("An error occurred when sending message {message:?} to monitoring: '{e}'."); - warn!(self.logger, "Event message error"; "error" => &error_msg); + warn!(self.logger, "Event message error"; "error" => ?e); }; } } diff --git a/mithril-aggregator/src/http_server/routes/statistics_routes.rs b/mithril-aggregator/src/http_server/routes/statistics_routes.rs index 5b68a1fcb7..a0cd122f4b 100644 --- a/mithril-aggregator/src/http_server/routes/statistics_routes.rs +++ b/mithril-aggregator/src/http_server/routes/statistics_routes.rs @@ -54,11 +54,8 @@ mod handlers { match event_transmitter.try_send(message.clone()) { Err(e) => { - let error_msg = format!( - "An error occurred when sending message {message:?} to monitoring: '{e}'." - ); - warn!(logger, "Event message error"; "error" => &error_msg); - Ok(reply::internal_server_error(error_msg)) + warn!(logger, "Event message error"; "error" => ?e); + Ok(reply::internal_server_error(e)) } Ok(_) => Ok(reply::empty(StatusCode::CREATED)), }