#[derive(Error,Debug)]
pub enum InternalError {
- #[error("Game corrupted by previous crash")]
- GameCorrupted,
#[error("Accounts file corrupted for acctid={0:?} account={1:?}")]
AccountsCorrupted(AccountId, Arc<AccountName>),
#[error("Error saving accounts file: {0}")]
#[derive(Error,Debug)]
pub enum InstanceLockError {
- GameCorrupted,
GameBeingDestroyed,
}
#[macro_export]
use InstanceLockError::*;
match e {
GameBeingDestroyed => $into::GameBeingDestroyed,
- GameCorrupted => InternalError::GameCorrupted.into(),
}
}
}
use crate::prelude::*;
use slotmap::dense as sm;
-use std::sync::PoisonError;
// ---------- newtypes and type aliases ----------
}
display_as_debug!{InstanceLockError}
-impl<X> From<PoisonError<X>> for InstanceLockError {
- fn from(_: PoisonError<X>) -> Self { Self::GameCorrupted }
-}
pub struct PrivateCaller(());
// outsiders cannot construct this
impl InstanceRef {
#[throws(InstanceLockError)]
pub fn lock(&self) -> InstanceGuard<'_> {
- let c = self.0.lock()?;
+ let c = self.0.lock().unwrap_or_else(|e| e.into_inner());
if !c.live { throw!(InstanceLockError::GameBeingDestroyed) }
InstanceGuard { c, gref: self.clone() }
}