From 91b6df23cdb88385c91b014ec0114e5b750aefd3 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Fri, 4 Sep 2020 21:44:06 +0100 Subject: [PATCH] fix EH --- src/api.rs | 17 ++++++++++++++--- src/updates.rs | 11 ++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/api.rs b/src/api.rs index 6158a134..570da5f0 100644 --- a/src/api.rs +++ b/src/api.rs @@ -21,6 +21,7 @@ trait ApiPieceOp : Debug { enum ApiPieceOpError { ReportViaResponse(#[from] OnlineError), ReportViaUpdate(#[from] PieceOpError), + PartiallyProcessed(PieceOpError, Vec), } display_as_debug!(ApiPieceOpError); @@ -101,7 +102,13 @@ fn api_piece_op(form : Json>) 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) { 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) } } diff --git a/src/updates.rs b/src/updates.rs index 61a2edcf..47de5eb7 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -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, 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(()) } -- 2.30.2