diff --git a/crates/lib/pager/src/client/pager.rs b/crates/lib/pager/src/client/pager.rs index def364e48a..64dd45fbde 100644 --- a/crates/lib/pager/src/client/pager.rs +++ b/crates/lib/pager/src/client/pager.rs @@ -59,9 +59,7 @@ impl Pager { &self, notification: NotificationDetails, ) -> Result { - self.client.send_page(¬ification) - .await - .map_err(PagerError::Service) + self.client.send_page(¬ification).await } /// Enqueue a page to be sent by the background worker thread. @@ -75,8 +73,7 @@ impl Pager { let queue = self.queue.as_ref() .ok_or(PagerSystemError::QueueFull)?; - let dropped = queue.push(notification) - .map_err(PagerError::System)?; + let dropped = queue.push(notification)?; if let Some(dropped) = dropped { log::warn!("Pager queue overflow: dropped '{}'", dropped.summary); diff --git a/crates/lib/pager/src/client/pager_client.rs b/crates/lib/pager/src/client/pager_client.rs index 8168ad569e..f74af414f3 100644 --- a/crates/lib/pager/src/client/pager_client.rs +++ b/crates/lib/pager/src/client/pager_client.rs @@ -5,6 +5,7 @@ use rootly_client::requests::create_alert::create_alert::{ create_alert, CreateAlertArgs, }; +use crate::error::pager_error::PagerError; use crate::error::pager_service_error::PagerServiceError; use crate::notification::notification_details::NotificationDetails; @@ -59,7 +60,7 @@ impl PagerClient { } /// Send a page immediately. - pub async fn send_page(&self, notification: &NotificationDetails) -> Result { + pub async fn send_page(&self, notification: &NotificationDetails) -> Result { match &self.client_config { PagerClientConfig::Rootly { .. } => self.send_page_via_rootly(notification).await, } @@ -68,7 +69,7 @@ impl PagerClient { async fn send_page_via_rootly( &self, notification: &NotificationDetails, - ) -> Result { + ) -> Result { let PagerClientConfig::Rootly { api_key, alert_urgency_id, @@ -118,7 +119,7 @@ impl PagerClient { } Err(err) => { error!("Failed to send page via Rootly: {}", err); - Err(PagerServiceError::RootlyError(err)) + Err(PagerError::Service(PagerServiceError::RootlyError(err))) } } } diff --git a/crates/lib/pager/src/worker/pager_worker_message_queue.rs b/crates/lib/pager/src/worker/pager_worker_message_queue.rs index 74d0bafc1a..a8e8f2ace2 100644 --- a/crates/lib/pager/src/worker/pager_worker_message_queue.rs +++ b/crates/lib/pager/src/worker/pager_worker_message_queue.rs @@ -3,6 +3,7 @@ use std::sync::{Arc, Mutex, Condvar}; use log::warn; +use crate::error::pager_error::PagerError; use crate::error::pager_system_error::PagerSystemError; use crate::notification::notification_details::NotificationDetails; @@ -35,7 +36,7 @@ impl PagerWorkerMessageQueue { /// /// If the queue is full, the oldest item is dropped and a warning is logged. /// Returns `Ok(Some(summary))` if an old item was evicted, `Ok(None)` otherwise. - pub fn push(&self, notification: NotificationDetails) -> Result, PagerSystemError> { + pub fn push(&self, notification: NotificationDetails) -> Result, PagerError> { let mut queue = self.inner.lock() .map_err(|e| PagerSystemError::MutexPoisoned(format!("push: {}", e)))?; @@ -57,7 +58,7 @@ impl PagerWorkerMessageQueue { /// Block until at least one item is available, then drain all items. /// /// Returns an error if the mutex is poisoned. - pub fn wait_and_drain(&self) -> Result, PagerSystemError> { + pub fn wait_and_drain(&self) -> Result, PagerError> { let mut queue = self.inner.lock() .map_err(|e| PagerSystemError::MutexPoisoned(format!("wait_and_drain lock: {}", e)))?; @@ -71,7 +72,7 @@ impl PagerWorkerMessageQueue { } /// Non-blocking drain of all currently queued items. - pub fn drain_available(&self) -> Result, PagerSystemError> { + pub fn drain_available(&self) -> Result, PagerError> { let mut queue = self.inner.lock() .map_err(|e| PagerSystemError::MutexPoisoned(format!("drain_available: {}", e)))?; Ok(queue.drain(..).collect()) @@ -84,13 +85,13 @@ impl PagerWorkerMessageQueue { self.condvar.notify_all(); } - pub fn len(&self) -> Result { + pub fn len(&self) -> Result { let queue = self.inner.lock() .map_err(|e| PagerSystemError::MutexPoisoned(format!("len: {}", e)))?; Ok(queue.len()) } - pub fn is_empty(&self) -> Result { + pub fn is_empty(&self) -> Result { Ok(self.len()? == 0) } }