From: Ian Jackson Date: Tue, 29 Mar 2022 23:46:41 +0000 (+0100) Subject: SSE: Adjust error handling somewhat X-Git-Tag: otter-1.0.0~81 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=26616134d0411b57aab5eaba66f434672d288c4c;p=otter.git SSE: Adjust error handling somewhat Have UpdateReader::read throw a bespoke error. Signed-off-by: Ian Jackson --- 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;