More explicit error in case of Mutex poisoning
This commit is contained in:
parent
370e0746dd
commit
e82cb82039
15
src/lib.rs
15
src/lib.rs
@ -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)"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user