chiark / gitweb /
Replace OE::PieceGone with POE::PieceGone
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 20 Mar 2021 22:06:57 +0000 (22:06 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 20 Mar 2021 22:06:57 +0000 (22:06 +0000)
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 <ijackson@chiark.greenend.org.uk>
daemon/api.rs
src/error.rs
src/global.rs
src/hidden.rs

index 859626e3958b065d7af55200192e085bc9e96e75..b90e401ab9bed9ff50d36769e9cf328c4fe353a2 100644 (file)
@@ -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<O: op::Complex>(form: Json<ApiPiece<O>>)
   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 {
index 03a947d4f8aaf22411a4eafa1d0954117928ed3c..64436285815b1b39f00cc58c4ecf5d47ec42e9d3 100644 (file)
@@ -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<T> 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]
index 4e31e66a669bac8fb8f8754109cdda787161e878..15c965fec395546109ead5e162f239c2ccdb9d9e 100644 (file)
@@ -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)?
   }
 }
 
index 47497751bd921d1c155fa145b1f16afce50e16f7..84b2248e6a8b4d85917fa38c9d11a4a621521396 100644 (file)
@@ -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!"))
     }