From 1fe174190f2cc6b64a7283b4b7abf287478551bf Mon Sep 17 00:00:00 2001 From: NicolasCantu Date: Tue, 4 Feb 2025 16:22:48 +0100 Subject: [PATCH] More explicit error in case of Mutex poisoning --- src/lib.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 237b1b2..9ed03d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,7 +26,18 @@ pub trait MutexExt { impl MutexExt for Mutex { fn lock_anyhow(&self) -> Result, anyhow::Error> { - self.lock() - .map_err(|e| anyhow::Error::msg(format!("Failed to lock: {}", e))) + match self.lock() { + Ok(guard) => Ok(guard), + Err(poison_error) => { + let data = poison_error.into_inner(); + + log::debug!( + "Failed to lock Mutex (poisoned). Data was: {:?}", + data + ); + + Err(anyhow::anyhow!("Failed to lock Mutex (poisoned)")) + } + } } }