chiark / gitweb /
noclient
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 4 Jul 2020 01:38:07 +0000 (02:38 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 4 Jul 2020 01:38:07 +0000 (02:38 +0100)
src/error.rs
src/global.rs
src/sse.rs

index aa90de14154523d8cf999615a88b904fe910d91f..5e1f075d9f307c33a4303c25a5c92ed2e44609b1 100644 (file)
@@ -8,12 +8,12 @@ pub enum OnlineError {
   #[error("Game corrupted by previous crash - consult administrator")]
   GameCorrupted,
   #[error("client session not recognised (terminated by server?)")]
-  NoClientSession,
+  NoClient,
   #[error("player not part of game (removed?)")]
   NoPlayer,
 }
 
-pub use OnlineError::{NoClientSession,NoPlayer};
+pub use OnlineError::{NoClient,NoPlayer};
 
 use OnlineError::*;
 
index c78530347afe384e531b0aaa7f6fc051656828c9..a932ed9a3521288005910dc1283c6004d96f5cd7 100644 (file)
@@ -70,13 +70,16 @@ lazy_static! {
 
 pub trait AccessId : Copy + Clone + 'static {
   fn global_tokens() -> &'static RwLock<TokenTable<Self>>;
+  const ERROR : OnlineError;
 }
 
 impl AccessId for PlayerId {
   fn global_tokens() -> &'static RwLock<TokenTable<Self>> { &GLOBAL.players }
+  const ERROR : OnlineError = NoPlayer;
 }
 impl AccessId for ClientId {
   fn global_tokens() -> &'static RwLock<TokenTable<Self>> { &GLOBAL.clients }
+  const ERROR : OnlineError = NoClient;
 }
 
 pub fn lookup_token<Id : AccessId>(s : &str)
@@ -103,12 +106,12 @@ const XXX_PLAYERS_TOKENS : &[(&str, &str)] = &[
 impl<'r, Id> FromParam<'r> for InstanceAccess<'r, Id>
   where Id : AccessId
 {
-  type Error = E;
-  #[throws(E)]
+  type Error = OE;
+  #[throws(OE)]
   fn from_param(param: &'r RawStr) -> Self {
     let g = Id::global_tokens().read().unwrap();
     let token = param.as_str();
-    let i = g.get(token).ok_or_else(|| anyhow!("unknown token"))?;
+    let i = g.get(token).ok_or(Id::ERROR)?;
     InstanceAccess { raw_token : token, i : i.clone() }
   }
 }
index 0a6ae5227b649e55d3f9c63568012434b0ef2901..0ac8fc1f283983515e3e5a127ef980967271a66a 100644 (file)
@@ -177,7 +177,7 @@ pub fn content(iad : InstanceAccessDetails<ClientId>, gen: Generation)
   let content = {
     let mut ig = iad.g.lock()?;
     let _g = &mut ig.gs;
-    let cl = ig.clients.get(client).ok_or(NoClientSession)?;
+    let cl = ig.clients.get(client).ok_or(NoClient)?;
     let player = cl.player;
     let ami = iad.g.clone();