--- /dev/null
+
+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 }
+}
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;
-
pub mod keydata;
pub mod updates;
pub mod sse;
+pub mod error;
}
*/
-#[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) {