More explicit error in case of Mutex poisoning

This commit is contained in:
NicolasCantu 2025-02-04 16:22:48 +01:00 committed by Nicolas Cantu
parent 370e0746dd
commit e82cb82039

View File

@ -26,7 +26,18 @@ pub trait MutexExt<T> {
impl<T: Debug> MutexExt<T> for Mutex<T> {
fn lock_anyhow(&self) -> Result<MutexGuard<T>, 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)"))
}
}
}
}