From e2ae9aa98c37317752524ccee3e80ef1b8735d78 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 13 Jul 2021 15:17:34 +0100 Subject: [PATCH] errors: Make check_held return Ia not Fatal Signed-off-by: Ian Jackson --- daemon/api.rs | 14 +++++++------- src/error.rs | 17 ++++++++++------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/daemon/api.rs b/daemon/api.rs index 30d144ae..45e184a0 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -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) } } } diff --git a/src/error.rs b/src/error.rs index 8387515d..31c5d2e0 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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; -- 2.30.2