From dc3e36796fb6fbf809c1fff257800adadf6af95e Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 9 Apr 2021 17:47:34 +0100 Subject: [PATCH] Abolish InstanceLockError, turning it into just GameBeingDestroyed Signed-off-by: Ian Jackson --- daemon/api.rs | 2 +- src/commands.rs | 4 +--- src/error.rs | 23 ++++------------------- src/global.rs | 8 +++----- src/prelude.rs | 1 - 5 files changed, 9 insertions(+), 29 deletions(-) diff --git a/daemon/api.rs b/daemon/api.rs index f79fe27a..e4a3c058 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -74,7 +74,7 @@ impl From<&OnlineErrorResponse> for rocket::http::Status { use OnlineError::*; match oe.0 { ServerFailure(_) => Status::InternalServerError, - NoClient | NoPlayer(_) | GameBeingDestroyed + NoClient | NoPlayer(_) | GameBeingDestroyed(_) => Status::NotFound, OE::PieceHeld | OE::PieceImmoveable | OE::OverlappingOccultation | OE::Occultation | diff --git a/src/commands.rs b/src/commands.rs index 455b1be4..ffd3ea33 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -187,7 +187,7 @@ pub enum MgmtError { MustSpecifyNick, AlreadyExists, NickCollision, - GameBeingDestroyed, + GameBeingDestroyed(#[from] GameBeingDestroyed), GameNotFound, GameCorrupted, AccountNotFound(#[from] AccountNotFound), @@ -221,8 +221,6 @@ impl From for MgmtError { } } -from_instance_lock_error!{MgmtError} - impl AccessTokenInfo { pub fn report(self) -> Vec { vec![ diff --git a/src/error.rs b/src/error.rs index 85202af6..8b2eac03 100644 --- a/src/error.rs +++ b/src/error.rs @@ -7,7 +7,7 @@ use crate::prelude::*; #[derive(Error,Debug)] pub enum OnlineError { #[error("Game in process of being destroyed")] - GameBeingDestroyed, + GameBeingDestroyed(#[from] GameBeingDestroyed), #[error("client session not recognised (terminated by server?)")] NoClient, #[error("player not part of game (removed?)")] @@ -31,7 +31,6 @@ pub enum OnlineError { #[error("UI operation not valid in the curret piece state")] BadPieceStateForOperation, } -from_instance_lock_error!{OnlineError} #[derive(Error,Debug)] pub enum InternalError { @@ -220,23 +219,9 @@ impl AggregatedIE { } } -#[derive(Error,Debug)] -pub enum InstanceLockError { - GameBeingDestroyed, -} -#[macro_export] -macro_rules! from_instance_lock_error { - ($into:ident) => { - impl From for $into { - fn from(e: InstanceLockError) -> $into { - use InstanceLockError::*; - match e { - GameBeingDestroyed => $into::GameBeingDestroyed, - } - } - } - } -} +#[derive(Error,Clone,Debug,Serialize,Deserialize)] +#[error("game is being destroyed")] +pub struct GameBeingDestroyed; pub trait ById { type Id; diff --git a/src/global.rs b/src/global.rs index 44b258c1..7093cedd 100644 --- a/src/global.rs +++ b/src/global.rs @@ -236,8 +236,6 @@ struct InstanceSaveAccesses, } -display_as_debug!{InstanceLockError} - pub struct PrivateCaller(()); // outsiders cannot construct this // workaround for inability to have private trait methods @@ -271,10 +269,10 @@ impl Debug for Instance { // ---------- Main API for instance lifecycle ---------- impl InstanceRef { - #[throws(InstanceLockError)] + #[throws(GameBeingDestroyed)] pub fn lock(&self) -> InstanceGuard<'_> { let c = self.0.lock(); - if !c.live { throw!(InstanceLockError::GameBeingDestroyed) } + if !c.live { throw!(GameBeingDestroyed) } InstanceGuard { c, gref: self.clone() } } @@ -294,7 +292,7 @@ impl InstanceWeakRef { } impl Unauthorised { - #[throws(InstanceLockError)] + #[throws(GameBeingDestroyed)] pub fn lock<'r>(&'r self) -> Unauthorised, A> { let must_not_escape = self.by_ref(Authorisation::authorise_any()); Unauthorised::of(must_not_escape.lock()?) diff --git a/src/prelude.rs b/src/prelude.rs index 96432335..1a1747c6 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -112,7 +112,6 @@ pub use base_misc::*; pub use crate::dbgc; pub use crate::{deref_to_field, deref_to_field_mut}; pub use crate::ensure_eq; -pub use crate::from_instance_lock_error; pub use crate::matches_doesnot; pub use crate::trace_dbg; pub use crate::{want, wantok, wants, want_let, want_failed_internal}; -- 2.30.2