chiark / gitweb /
fix EH
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 4 Sep 2020 20:44:06 +0000 (21:44 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Fri, 4 Sep 2020 20:44:06 +0000 (21:44 +0100)
src/api.rs
src/updates.rs

index 6158a134229908e74aa8fb801d6ce095fc90ee84..570da5f02aca2f39662d034c9c45eed861129a3e 100644 (file)
@@ -21,6 +21,7 @@ trait ApiPieceOp : Debug {
 enum ApiPieceOpError {
   ReportViaResponse(#[from] OnlineError),
   ReportViaUpdate(#[from] PieceOpError),
+  PartiallyProcessed(PieceOpError, Vec<LogEntry>),
 }
 display_as_debug!(ApiPieceOpError);
 
@@ -101,7 +102,13 @@ fn api_piece_op<O: ApiPieceOp>(form : Json<ApiPiece<O>>)
     Err(ReportViaUpdate(poe)) => {
       PrepareUpdatesBuffer::piece_report_error(
         &mut ig, poe,
-        piece, player, client, &lens
+        piece, vec![], client, &lens
+      )?;
+    },
+    Err(PartiallyProcessed(poe, logents)) => {
+      PrepareUpdatesBuffer::piece_report_error(
+        &mut ig, poe,
+        piece, logents, client, &lens
       )?;
     },
     Err(ReportViaResponse(err)) => {
@@ -221,12 +228,16 @@ impl ApiPieceOp for ApiPieceMove {
         -> (PieceUpdateOp<()>, Vec<LogEntry>) {
     let pc = gs.pieces.byid_mut(piece).unwrap();
     let (pos, clamped) = self.0.clamped(gs.table_size);
+    let logents = vec![];
     pc.pos = pos;
     if clamped {
-      Err(ApiPieceOpError::ReportViaUpdate(PieceOpError::PosOffTable))?;
+      throw!(ApiPieceOpError::PartiallyProcessed(
+        PieceOpError::PosOffTable,
+        logents,
+      ));
     }
     let update = PieceUpdateOp::Move(self.0);
-    (update, vec![])
+    (update, logents)
   }
 }
 
index 61a2edcf30938d3605c7ccb7617906d958f880a5..47de5eb71ef7306f7fb0594598bc8c3648eb5c5c 100644 (file)
@@ -223,8 +223,8 @@ impl<'r> PrepareUpdatesBuffer<'r> {
     Self::new(ig, None, Some(1))
   }
   pub fn piece_report_error(ig: &mut Instance,
-                            error: PieceOpError,
-                            piece: PieceId, player: PlayerId, client: ClientId,
+                            error: PieceOpError, piece: PieceId,
+                            logents: Vec<LogEntry>, client: ClientId,
                             lens: &dyn Lens) -> Result<(),OE> {
     let mut buf = PrepareUpdatesBuffer::new_for_error(ig);
     let update = buf.piece_update_fallible(
@@ -245,11 +245,8 @@ impl<'r> PrepareUpdatesBuffer<'r> {
       },
       _ => panic!(),
     };
-    let update = PreparedUpdate { gen: buf.gen, us : vec![ update ] };
-    assert!(buf.us.is_empty());
-    mem::drop(buf);
-    let pl_updates = ig.updates.get_mut(player).ok_or(OE::NoPlayer)?;
-    pl_updates.push(Arc::new(update));
+    buf.us.push(update);
+    buf.log_updates(logents);
     Ok(())
   }