From: Ian Jackson Date: Sat, 20 Mar 2021 22:06:57 +0000 (+0000) Subject: Replace OE::PieceGone with POE::PieceGone X-Git-Tag: otter-0.5.0~605 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=54ecef508f589aa06bb2f40376e69eeb097e144a;p=otter.git Replace OE::PieceGone with POE::PieceGone The client might experience PieceGone due to occultation, so that's not an error. The Delete update in the updates stream will generally tell them what's going on. Signed-off-by: Ian Jackson --- diff --git a/daemon/api.rs b/daemon/api.rs index 859626e3..b90e401a 100644 --- a/daemon/api.rs +++ b/daemon/api.rs @@ -76,7 +76,7 @@ impl From<&OnlineErrorResponse> for rocket::http::Status { ServerFailure(_) => Status::InternalServerError, NoClient | NoPlayer(_) | GameBeingDestroyed => Status::NotFound, - OE::PieceHeld | OE::PieceGone | + OE::PieceHeld | OE::OverlappingOccultation | OE::Occultation | OE::BadPieceStateForOperation => Status::Conflict, @@ -120,13 +120,13 @@ fn api_piece_op(form: Json>) let iplayers = &g.iplayers; let _ = iplayers.byid(player)?; let gpl = gs.players.byid(player)?; - let piece = vpiece_decode(gs, player, gpl, form.piece) - .ok_or(OE::PieceGone)?; + let piece = vpiece_decode(gs, player, gpl, form.piece); + let piece = if let Some(piece) = piece { piece } else { return Ok(()) }; let was_held = gs.pieces.get(piece).as_ref().map(|gpc| gpc.held); use ApiPieceOpError::*; match (||{ - let ipc = ipieces.get(piece).ok_or(OnlineError::PieceGone)?; + let ipc = ipieces.get(piece).ok_or(POE::PieceGone)?; let gpc = gs.pieces.byid_mut(piece)?; let q_gen = form.gen; @@ -309,7 +309,7 @@ api_route!{ let gpl = players.byid_mut(player)?; let pri = piece_pri(ioccults, &gs.occults, player, gpl, piece, gpc, ipc) - .ok_or(OE::PieceGone)?; + .ok_or(POE::PieceGone)?; let pcs = pri.describe(ioccults, gpc, ipc).0; @@ -348,7 +348,7 @@ api_route!{ ioccults,gpl,gpc,ipc, "released" )?; - let who_by = who_by.ok_or(OE::PieceGone)?; + let who_by = who_by.ok_or(POE::PieceGone)?; if gpc.held != Some(player) { throw!(OnlineError::PieceHeld) } gpc.held = None; @@ -499,7 +499,7 @@ api_route!{ player, gs.players.byid_mut(player)?, piece, gs.pieces.byid(piece)?, ipc) - .ok_or(OE::PieceGone)?; + .ok_or(POE::PieceGone)?; let y = { use PriOG::*; match pri.occulted { diff --git a/src/error.rs b/src/error.rs index 03a947d4..64436285 100644 --- a/src/error.rs +++ b/src/error.rs @@ -19,8 +19,6 @@ pub enum OnlineError { #[error("JSON deserialisation error: {0:?}")] BadJSON(serde_json::Error), #[error("referenced piece is gone (maybe race)")] - PieceGone, // xxx this needs to go away and be done via updates stream - #[error("improper piece hold status for op (maybe race)")] PieceHeld, #[error("improper UI operation")] BadOperation, @@ -155,6 +153,7 @@ display_as_debug!{PieceOpErrorPartiallyProcessed} pub enum PieceOpError { Conflict, PosOffTable, + PieceGone, } display_as_debug!{PieceOpError} @@ -256,8 +255,8 @@ impl IdForById for T where T: AccessId { } impl IdForById for PieceId { - type Error = OE; - const ERROR: OE = OE::PieceGone; + type Error = POE; + const ERROR: POE = POE::PieceGone; } #[macro_export] diff --git a/src/global.rs b/src/global.rs index 4e31e66a..15c965fe 100644 --- a/src/global.rs +++ b/src/global.rs @@ -1309,14 +1309,14 @@ impl GPieces { impl ById for GPieces { type Id = PieceId; type Entry = GPiece; - type Error = OnlineError; - #[throws(OE)] + type Error = PieceOpError; + #[throws(POE)] fn byid(&self, piece: PieceId) -> &GPiece { - self.get(piece).ok_or(OE::PieceGone)? + self.get(piece).ok_or(POE::PieceGone)? } - #[throws(OE)] + #[throws(POE)] fn byid_mut(&mut self, piece: PieceId) -> &mut GPiece { - self.get_mut(piece).ok_or(OE::PieceGone)? + self.get_mut(piece).ok_or(POE::PieceGone)? } } diff --git a/src/hidden.rs b/src/hidden.rs index 47497751..84b2248e 100644 --- a/src/hidden.rs +++ b/src/hidden.rs @@ -678,7 +678,8 @@ pub fn create_occultation( views: OccultationViews, ) -> Vec<(PieceId, PieceUpdateOps)> { { - let ogpc = gpieces.byid(occulter)?; + let ogpc = gpieces.get(occulter).ok_or_else( + ||internal_logic_error("create occultation with non-piece"))?; if ogpc.occult.active.is_some() { throw!(internal_logic_error("re-occulting!")) }