chiark / gitweb /
errors: Make check_held return Ia not Fatal
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 13 Jul 2021 14:17:34 +0000 (15:17 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 13 Jul 2021 14:17:34 +0000 (15:17 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/api.rs
src/error.rs

index 30d144ae454b1a6e405245f7c49e7c54f16b1f01..45e184a0616a4f78365e0ddf15b85b27293e7d7a 100644 (file)
@@ -39,10 +39,10 @@ mod op {
   use super::*;
 
   pub trait Core: Debug { 
-    #[throws(Fatal)]
+    #[throws(Inapplicable)]
     fn check_held(&self, pc: &GPiece, player: PlayerId) {
       if pc.held != None && pc.held != Some(player) {
-        throw!(Fatal::PieceHeld)
+        throw!(Ia::PieceHeld)
       }
     }
   }
@@ -305,7 +305,7 @@ api_route!{
   }
 
   impl op::Core as {
-    #[throws(Fatal)]
+    #[throws(Ia)]
     fn check_held(&self, _pc: &GPiece, _player: PlayerId) { }
   }
 
@@ -464,18 +464,18 @@ api_route!{
   struct ApiPieceMove(Pos);
 
   impl op::Core as {
-    #[throws(Fatal)]
+    #[throws(Ia)]
     fn check_held(&self, gpc: &GPiece, player: PlayerId) {
       // This will ensure that occultations are (in general) properly
       // updated, because the player will (have to) release the thing
       // again
-      if gpc.held != Some(player) { throw!(Fatal::PieceHeld) }
-      if gpc.occult.is_active() { throw!(OE::Occultation) }
+      if gpc.held != Some(player) { throw!(Ia::PieceNotHeld) }
+      if gpc.occult.is_active() { throw!(Ia::Occultation) }
       if matches_doesnot!(
         gpc.moveable(),
         = PieceMoveable::No,
         ! PieceMoveable::Yes | PieceMoveable::IfWresting,
-      ) { throw!(OE::PieceImmoveable) }
+      ) { throw!(Ia::PieceImmoveable) }
     }
   }
 
index 8387515dd9eb3173c0146bf1a25ff69be49aa178..31c5d2e093f1ef9872e738dfa65152a52fd32015 100644 (file)
@@ -175,13 +175,16 @@ display_as_debug!{PieceOpErrorPartiallyProcessed}
 
 #[derive(Error,Debug,Serialize,Copy,Clone)]
 pub enum Inapplicable {
-  #[error("simultaneous update")]         Conflict,
-  #[error("position off table")]          PosOffTable,
-  #[error("piece gone")]                  PieceGone,
-  #[error("prevented by occultation")]    Occultation,
-  #[error("piece may not be rotated")]    PieceUnrotateable,
-  #[error("occulter already rotated")]    OcculterAlreadyRotated,
-  #[error("overfull, cannot organise")]   OrganisedPlacementOverfull,
+  #[error("simultaneous update")]           Conflict,
+  #[error("position off table")]            PosOffTable,
+  #[error("piece gone")]                    PieceGone,
+  #[error("piece held by another player")]  PieceHeld,
+  #[error("piece not held by your")]        PieceNotHeld,
+  #[error("prevented by occultation")]      Occultation,
+  #[error("piece may not be rotated")]      PieceUnrotateable,
+  #[error("piece may not be moved")]        PieceImmoveable,
+  #[error("occulter already rotated")]      OcculterAlreadyRotated,
+  #[error("overfull, cannot organise")]     OrganisedPlacementOverfull,
 }
 
 pub type StartupError = anyhow::Error;