From 26616134d0411b57aab5eaba66f434672d288c4c Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 30 Mar 2022 00:46:41 +0100 Subject: [PATCH] SSE: Adjust error handling somewhat Have UpdateReader::read throw a bespoke error. Signed-off-by: Ian Jackson --- daemon/sse.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/daemon/sse.rs b/daemon/sse.rs index 575ed482..ca1b7e09 100644 --- a/daemon/sse.rs +++ b/daemon/sse.rs @@ -92,8 +92,15 @@ trait InfallibleBufRead: BufRead { } impl InfallibleBufRead for io::Cursor where io::Cursor: BufRead { } impl InfallibleBufRead for &mut T where T: InfallibleBufRead { } +#[derive(Error,Debug)] +pub enum SSEUpdateGenerationError { + ImpossibleIoWriteError(#[from] io::Error), // write of Vec failed + GameBeingDestroyed(#[from] GameBeingDestroyed), +} +display_as_debug!{SSEUpdateGenerationError} + impl UpdateReader { - #[throws(io::Error)] + #[throws(SSEUpdateGenerationError)] async fn read(&mut self) -> BufForSend { let mut buf = BufForRead::default(); @@ -101,8 +108,7 @@ impl UpdateReader { return buf.just_copy_from(ending); } - let mut ig = self.gref.lock() - .map_err(|e| self.trouble("game corrupted", &e))?; + let mut ig = self.gref.lock()?; if self.init_confirmation_send.next().is_some() { write!(buf, "event: commsworking\n\ @@ -114,6 +120,8 @@ impl UpdateReader { let iplayer = &mut match g.iplayers.get_mut(self.player) { Some(x) => x, None => { + // Ideally this would be handled by us throwing, and + // the content unfold handling the error. let data = format!("event: player-gone\n\ data: No longer in the game\n\n") .into_bytes().into_boxed_slice(); @@ -198,7 +206,7 @@ impl UpdateReader { #[throws(Fatal)] pub fn content(iad: InstanceAccessDetails, gen: Generation) - -> Pin>>> + -> Pin>>> { let client = iad.ident; -- 2.30.2