chiark / gitweb /
errors
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 4 Jul 2020 01:33:48 +0000 (02:33 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 4 Jul 2020 01:33:53 +0000 (02:33 +0100)
src/error.rs [new file with mode: 0644]
src/imports.rs
src/lib.rs
src/sse.rs

diff --git a/src/error.rs b/src/error.rs
new file mode 100644 (file)
index 0000000..aa90de1
--- /dev/null
@@ -0,0 +1,22 @@
+
+use crate::imports::*;
+
+use std::sync::PoisonError;
+
+#[derive(Error,Debug)]
+pub enum OnlineError {
+  #[error("Game corrupted by previous crash - consult administrator")]
+  GameCorrupted,
+  #[error("client session not recognised (terminated by server?)")]
+  NoClientSession,
+  #[error("player not part of game (removed?)")]
+  NoPlayer,
+}
+
+pub use OnlineError::{NoClientSession,NoPlayer};
+
+use OnlineError::*;
+
+impl<X> From<PoisonError<X>> for OnlineError {
+  fn from(_: PoisonError<X>) -> OnlineError { GameCorrupted }
+}
index 625df08f388fcffd0370239d5c54a7c413e79a9e..55a93c71465c318261c7c27867a1607623cc9e0f 100644 (file)
@@ -45,12 +45,14 @@ pub use crate::pieces::*;
 pub use crate::keydata::*;
 pub use crate::updates::*;
 pub use crate::sse;
+pub use crate::error::*;
 
 pub type E = anyhow::Error;
 pub type AE = anyhow::Error;
 
+pub type OE = OnlineError;
+
 pub type SvgData = Vec<u8>;
 pub type Coord = isize;
 pub type Pos = [Coord; 2];
 pub type Colour = String;
-
index f8bd1e1aa57c55f44356e79d82455b8455469cb6..1a8627dfa0f22880abbd885a41d17ddcd6f64ff1 100644 (file)
@@ -6,3 +6,4 @@ pub mod gamestate;
 pub mod keydata;
 pub mod updates;
 pub mod sse;
+pub mod error;
index 91e827f63e724fb54b4afea39eb6ee6e447cf641..0a6ae5227b649e55d3f9c63568012434b0ef2901 100644 (file)
@@ -169,19 +169,19 @@ struct APIForm {
 }
  */
 
-#[throws(E)]
+#[throws(OE)]
 pub fn content(iad : InstanceAccessDetails<ClientId>, gen: Generation)
   -> impl Read {
   let client = iad.ident;
 
   let content = {
-    let mut ig = iad.g.lock().map_err(|e| anyhow!("lock poison {:?}",&e))?;
+    let mut ig = iad.g.lock()?;
     let _g = &mut ig.gs;
-    let cl = ig.clients.get(client).ok_or_else(|| anyhow!("no client"))?;
+    let cl = ig.clients.get(client).ok_or(NoClientSession)?;
     let player = cl.player;
     let ami = iad.g.clone();
 
-    let log = &ig.updates.get(player).ok_or_else(|| anyhow!("no plaeyr"))?.log;
+    let log = &ig.updates.get(player).ok_or(NoPlayer)?.log;
 
     let to_send = match log.into_iter().rev()
       .find(|(_,update)| update.gen < gen) {