chiark / gitweb /
Abolish InstanceLockError, turning it into just GameBeingDestroyed
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 9 Apr 2021 16:47:34 +0000 (17:47 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 9 Apr 2021 16:47:34 +0000 (17:47 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/api.rs
src/commands.rs
src/error.rs
src/global.rs
src/prelude.rs

index f79fe27aadcfedc916407a74fdcba594e5ac1e62..e4a3c058712154ae4d18a3317e863e9e992803af 100644 (file)
@@ -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 |
index 455b1be47e0499876f94d2fc8bc3d456641de637..ffd3ea33c6cc381b95a02c7395c83d6e7abb0949 100644 (file)
@@ -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<InternalError> for MgmtError {
   }
 }
 
-from_instance_lock_error!{MgmtError}
-
 impl AccessTokenInfo {
   pub fn report(self) -> Vec<String> {
     vec![
index 85202af66c269945717f3c493d94fdbbb19b9270..8b2eac03fd913bc4e36330c4792ffeee36972157 100644 (file)
@@ -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<InstanceLockError> 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;
index 44b258c1ef554ecf48064266ec8d6c61dcfb3915..7093ceddb805b98620c89853aa198e68728eb483 100644 (file)
@@ -236,8 +236,6 @@ struct InstanceSaveAccesses<RawTokenStr, PiecesLoadedRef, OccultIlksRef,
   pub links: Arc<LinksTable>,
 }
 
-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<A> Unauthorised<InstanceRef, A> {
-  #[throws(InstanceLockError)]
+  #[throws(GameBeingDestroyed)]
   pub fn lock<'r>(&'r self) -> Unauthorised<InstanceGuard<'r>, A> {
     let must_not_escape = self.by_ref(Authorisation::authorise_any());
     Unauthorised::of(must_not_escape.lock()?)
index 964323358f2ef317fe45ba1a9fa6de4ce0b59e1b..1a1747c660fbf7ab2df8dbf56d244dabd1f9e270 100644 (file)
@@ -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};