chiark / gitweb /
errors: Rename error types according to new scheme
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 13 Jul 2021 14:07:43 +0000 (15:07 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 13 Jul 2021 14:07:43 +0000 (15:07 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/api.rs
daemon/main.rs
src/error.rs
src/global.rs
src/hidden.rs
src/organise.rs
src/prelude.rs
src/updates.rs

index ac07981204878eb5ff56b409e56fbeb01517c02f..8e4a597d04a12668ad4d2d6dd687f09a9267230b 100644 (file)
@@ -39,10 +39,10 @@ mod op {
   use super::*;
 
   pub trait Core: Debug { 
-    #[throws(OnlineError)]
+    #[throws(Fatal)]
     fn check_held(&self, pc: &GPiece, player: PlayerId) {
       if pc.held != None && pc.held != Some(player) {
-        throw!(OnlineError::PieceHeld)
+        throw!(Fatal::PieceHeld)
       }
     }
   }
@@ -67,11 +67,11 @@ mod op {
 
 #[derive(Error,Debug)]
 #[error("{0}")]
-pub struct OnlineErrorResponse(#[from] OnlineError);
+pub struct FatalErrorResponse(#[from] Fatal);
 
-impl From<&OnlineErrorResponse> for rocket::http::Status {
-  fn from(oe: &OnlineErrorResponse) -> rocket::http::Status {
-    use OnlineError::*;
+impl From<&FatalErrorResponse> for rocket::http::Status {
+  fn from(oe: &FatalErrorResponse) -> rocket::http::Status {
+    use Fatal::*;
     match oe.0 {
       ServerFailure(_) => Status::InternalServerError,
       NoClient | NoPlayer(_) | GameBeingDestroyed(_)
@@ -86,7 +86,7 @@ impl From<&OnlineErrorResponse> for rocket::http::Status {
   }
 }
 
-impl<'r> Responder<'r> for OnlineErrorResponse {
+impl<'r> Responder<'r> for FatalErrorResponse {
   #[throws(Status)]
   fn respond_to(self, req: &Request) -> Response<'r> {
     let msg = format!("Online-layer error\n{:?}\n{}\n", self, self);
@@ -123,7 +123,6 @@ fn api_piece_op<O: op::Complex>(form: Json<ApiPiece<O>>)
   let piece = vpiece_decode(gs, player, gpl, form.piece);
   if_let!{ Some(piece) = piece; else return Ok(()) }
   let was_held = gs.pieces.get(piece).as_ref().map(|gpc| gpc.held);
-  use ApiPieceOpError::*;
 
   match (||{
     let ipc = ipieces.get(piece).ok_or(POE::PieceGone)?;
@@ -136,7 +135,7 @@ fn api_piece_op<O: op::Complex>(form: Json<ApiPiece<O>>)
 
     debug!("client={:?} pc.lastclient={:?} pc.gen_before={:?} pc.gen={:?} q_gen={:?} u_gen={:?}", &client, &gpc.lastclient, &gpc.gen_before_lastclient, &gpc.gen, &q_gen, &u_gen);
 
-    if u_gen > q_gen { throw!(PieceOpError::Conflict) }
+    if u_gen > q_gen { throw!(Inapplicable::Conflict) }
     trace_dbg!("form.op", player, piece, &form.op, &gpc);
     form.op.check_held(gpc,player)?;
     let update =
@@ -148,21 +147,21 @@ fn api_piece_op<O: op::Complex>(form: Json<ApiPiece<O>>)
       })?;
     Ok::<_,ApiPieceOpError>(update)
   })() {
-    Err(ReportViaUpdate(poe)) => {
+    Err(APOE::Inapplicable(poe)) => {
       PrepareUpdatesBuffer::piece_report_error(
         &mut ig, poe,
         piece, vec![], POEPP::Unprocessed, client, form.cseq,
       )?;
       debug!("api_piece_op Err(RVU): {:?}", &form);
     },
-    Err(PartiallyProcessed(poe, logents)) => {
+    Err(APOE::PartiallyProcessed(poe, logents)) => {
       PrepareUpdatesBuffer::piece_report_error(
         &mut ig, poe,
         piece, logents, POEPP::Partially, client, form.cseq,
       )?;
       debug!("api_piece_op Err(PP): {:?}", &form);
     },
-    Err(ReportViaResponse(err)) => {
+    Err(APOE::Fatal(err)) => {
       warn!("api_piece_op ERROR {:?}: {:?}", &form, &err);
       Err(err)?;
     },
@@ -289,7 +288,7 @@ api_route!{
         "grasped"
       )?;
 
-      if gpc.held.is_some() { throw!(OnlineError::PieceHeld) }
+      if gpc.held.is_some() { throw!(Fatal::PieceHeld) }
       gpc.held = Some(player);
     
       let update = PieceUpdateOp::ModifyQuiet(());
@@ -306,7 +305,7 @@ api_route!{
   }
 
   impl op::Core as {
-    #[throws(OnlineError)]
+    #[throws(Fatal)]
     fn check_held(&self, _pc: &GPiece, _player: PlayerId) { }
   }
 
@@ -388,7 +387,7 @@ api_route!{
 
       then {
         let z = gs.max_z.z.clone_mut().increment().map_err(
-          |e| APOE::ReportViaResponse(IE::from(e).into()))?;
+          |e| APOE::Fatal(IE::from(e).into()))?;
         Some(ZLevel { z, zg: gs.gen })
       }
       else { None }
@@ -403,7 +402,7 @@ api_route!{
     )?;
     let who_by = who_by.ok_or(POE::PieceGone)?;
 
-    if gpc.held != Some(player) { throw!(OnlineError::PieceHeld) }
+    if gpc.held != Some(player) { throw!(Fatal::PieceHeld) }
     gpc.held = None;
 
     let wrc = if let Some(zlevel) = new_z {
@@ -433,7 +432,7 @@ api_route!{
         to_recalculate,
         piece,
         vanilla,
-      ).map_err(|e| OnlineError::from(e))?;
+      ).map_err(|e| Fatal::from(e))?;
 
     update
   }
@@ -465,12 +464,12 @@ api_route!{
   struct ApiPieceMove(Pos);
 
   impl op::Core as {
-    #[throws(OnlineError)]
+    #[throws(Fatal)]
     fn check_held(&self, gpc: &GPiece, player: PlayerId) {
       // This will ensure that occultations are (in general) properly
       // updated, because the player will (have to) release the thing
       // again
-      if gpc.held != Some(player) { throw!(OnlineError::PieceHeld) }
+      if gpc.held != Some(player) { throw!(Fatal::PieceHeld) }
       if gpc.occult.is_active() { throw!(OE::Occultation) }
       if matches_doesnot!(
         gpc.moveable(),
@@ -491,7 +490,7 @@ api_route!{
         Err(pote) => {
           gpc.pos = pote.clamped;
           throw!(ApiPieceOpError::PartiallyProcessed(
-            PieceOpError::PosOffTable,
+            Inapplicable::PosOffTable,
             logents,
           ));
         }
index 0b997e51a1582d56b16163d0fb8cbc85cb746c6a..5c20e1af8f08a225f921b92e9f91cd005f923162 100644 (file)
@@ -28,10 +28,10 @@ pub use rocket_contrib::templates::Engines;
 pub use rocket_contrib::templates::Template;
 
 pub use crate::api::InstanceAccess;
-pub use crate::api::{OnlineErrorResponse};
+pub use crate::api::{FatalErrorResponse};
 pub use crate::cmdlistener::*;
 
-pub type OER = OnlineErrorResponse;
+pub type OER = FatalErrorResponse; // xxx rename this alias
 
 use rocket::fairing;
 use rocket::response::Content;
index 15a3a07193dc60bad21f7d88049684a176cca3f6..22dfc84c4cf775944d0d333f3ed59b73d7794f5f 100644 (file)
@@ -5,7 +5,7 @@
 use crate::prelude::*;
 
 #[derive(Error,Debug)]
-pub enum OnlineError {
+pub enum Fatal { // Includes _bogus_ client updates, see PROTOCOL.md
   #[error("Game in process of being destroyed")]
   GameBeingDestroyed(#[from] GameBeingDestroyed),
   #[error("client session not recognised (terminated by server?)")]
@@ -17,17 +17,17 @@ pub enum OnlineError {
   #[error("JSON deserialisation error: {0}")]
   BadJSON(serde_json::Error),
   #[error("referenced piece is gone (maybe race)")]
-  PieceHeld,
+  PieceHeld, // xxx should be _inapplicable_
   #[error("improper UI operation")]
-  PieceImmoveable,
+  PieceImmoveable, // xxx should be _inapplicable_
   #[error("improper UI operation")]
-  BadOperation,
+  BadOperation, // xxx should be _inapplicable_
   #[error("overlapping occultation")]
-  OverlappingOccultation,
+  OverlappingOccultation, // xxx should be _inapplicable_
   #[error("piece is occulting, or occulted")]
-  Occultation,
+  Occultation, // xxx should be _inapplicable_
   #[error("UI operation not valid in the curret piece state")]
-  BadPieceStateForOperation,
+  BadPieceStateForOperation, // xxx should be _inapplicable_
 }
 
 #[derive(Error,Debug)]
@@ -130,26 +130,26 @@ impl From<InternalError> for SpecError {
 
 #[derive(Error,Debug)]
 pub enum ApiPieceOpError {
-  ReportViaResponse(#[from] OnlineError),
-  ReportViaUpdate(#[from] PieceOpError),
+  Fatal(#[from] Fatal),
+  Inapplicable(#[from] Inapplicable),
 
   /// This error is always generated in the context of a piece
   /// operation by a particular client.  It corresponds roughly to a
   /// PieceUpdateFromOp for other clients of (Unpredicable,
   /// PieceUpdateOp::Modify, ..).
   /// For this client it is that but also an error report.
-  PartiallyProcessed(PieceOpError, Vec<LogEntry>),
+  PartiallyProcessed(Inapplicable, Vec<LogEntry>),
 }
 display_as_debug!(ApiPieceOpError);
 
 impl From<PlayerNotFound> for ApiPieceOpError {
   fn from(x: PlayerNotFound) -> ApiPieceOpError {
-    ApiPieceOpError::ReportViaResponse(x.into())
+    ApiPieceOpError::Fatal(x.into())
   }
 }
 impl From<InternalError> for ApiPieceOpError {
   fn from(x: InternalError) -> ApiPieceOpError {
-    ApiPieceOpError::ReportViaResponse(x.into())
+    ApiPieceOpError::Fatal(x.into())
   }
 }
 
@@ -159,7 +159,7 @@ pub enum ErrorSignaledViaUpdate<POEPU: Debug> {
   PlayerRemoved, // appears only in streams for applicable player
   TokenRevoked, // appears only in streams for applicable player
   PieceOpError {
-    error: PieceOpError,
+    error: Inapplicable,
     partially: PieceOpErrorPartiallyProcessed,
     state: POEPU,
   },
@@ -174,7 +174,7 @@ pub enum PieceOpErrorPartiallyProcessed {
 display_as_debug!{PieceOpErrorPartiallyProcessed}
 
 #[derive(Error,Debug,Serialize,Copy,Clone)]
-pub enum PieceOpError {
+pub enum Inapplicable {
   Conflict,
   PosOffTable,
   PieceGone,
@@ -183,11 +183,11 @@ pub enum PieceOpError {
   OcculterAlreadyRotated,
   OrganisedPlacementOverfull,
 }
-display_as_debug!{PieceOpError}
+display_as_debug!{Inapplicable}
 
 pub type StartupError = anyhow::Error;
 
-pub use OnlineError::{NoClient,NoPlayer};
+pub use Fatal::{NoClient,NoPlayer};
 
 pub enum AggregatedIE {
   Ok,
index 354ef4ae32fc0208e4a3bea60394bdfaff0ebfb9..76e95dbc09de8a9445baa4000e2c1632e91b7271 100644 (file)
@@ -1296,7 +1296,7 @@ pub fn load_games(accounts: &mut AccountsGuard,
 pub type TokenTable<Id> = HashMap<RawToken, InstanceAccessDetails<Id>>;
 
 pub trait AccessId: Copy + Clone + 'static {
-  type Error: Into<OnlineError>;
+  type Error: Into<Fatal>;
   const ERROR: Self::Error;
   fn global_tokens(_:PrivateCaller) -> &'static RwLock<TokenTable<Self>>;
   fn tokens_registry(ig: &mut Instance, _:PrivateCaller)
@@ -1321,8 +1321,8 @@ impl AccessId for PlayerId {
   }
 }
 impl AccessId for ClientId {
-  type Error = OnlineError;
-  const ERROR: OnlineError = NoClient;
+  type Error = Fatal;
+  const ERROR: Fatal = NoClient;
   fn global_tokens(_: PrivateCaller) -> &'static RwLock<TokenTable<Self>> {
     &GLOBAL.clients
   }
@@ -1416,7 +1416,7 @@ impl GPieces {
 impl ById for GPieces {
   type Id = PieceId;
   type Entry = GPiece;
-  type Error = PieceOpError;
+  type Error = Inapplicable;
   #[throws(POE)]
   fn byid(&self, piece: PieceId) -> &GPiece {
     self.get(piece).ok_or(POE::PieceGone)?
index b62d31e0c80eb58eb28b312e270968d3a1bd4199..3228fda03a6ae24a5966654acf767816c044b289 100644 (file)
@@ -428,7 +428,7 @@ impl GPiece {
   }
 
   pub fn occulter_check_unrotated(&self, _:ShowUnocculted)
-      -> Result<OcculterRotationChecked, PieceOpError> {
+      -> Result<OcculterRotationChecked, Inapplicable> {
     if self.angle.is_rotated() { Err(POE::OcculterAlreadyRotated) }
     else { Ok(OcculterRotationChecked(())) }
   }
@@ -881,7 +881,7 @@ impl OccultationViewDef for OwnerOccultationView {
   } }
 }
 
-#[throws(OnlineError)]
+#[throws(Fatal)]
 pub fn create_occultation(
   gen: &mut UniqueGenGen,
   max_z: &mut ZLevel,
index 59550e2e88a58e57b76be24276ffc24ebfe1e0e7..306193403d339566dde7f552f3da2a8c4ebb2697 100644 (file)
@@ -106,7 +106,7 @@ type Primary<'pe> = IndexVec<InHand, PrimaryEnt<'pe>>;
 type ZLevels = IndexVec<InHand, ZLevel>;
 type OrderTable = IndexVec<InHand, InHand>;
 
-#[throws(PieceOpError)]
+#[throws(Inapplicable)]
 fn recover_order(region: &Rect, pieces: &Primary, zlevels: &ZLevels)
                 -> OrderTable
 {
@@ -290,11 +290,11 @@ pub fn ui_operation(a: &mut ApiPieceOpArgs<'_>, _: OcculterRotationChecked,
   for &pos in &layout {
     // Some sanity checks
     pos.clamped(gs.table_size).map_err(
-      |_| APOE::ReportViaUpdate(POE::PosOffTable))?;
+      |_| APOE::Inapplicable(POE::PosOffTable))?;
     match gs.occults.pos_occulter(&gs.occults, pos)? {
       None => {},
       Some(occulter) if occulter == apiece => {},
-      Some(_) => throw!(APOE::ReportViaUpdate(POE::Occultation)),
+      Some(_) => throw!(APOE::Inapplicable(POE::Occultation)),
     };
   }
 
index c420b4b1270c16919e5e574a6acaca022832a579..afc9aada36c259ea9513c71df63f7789a807995d 100644 (file)
@@ -196,8 +196,8 @@ pub type PUM = ProgressUpdateMode;
 pub type APOE = ApiPieceOpError;
 pub type ESVU<POEPU> = ErrorSignaledViaUpdate<POEPU>;
 pub type IE = InternalError;
-pub type OE = OnlineError;
-pub type POE = PieceOpError;
+pub type OE = Fatal; // xxx get rid of this alyas when we've cleaned up Fatal
+pub type POE = Inapplicable; // xxx rename this alias
 pub type POEPP = PieceOpErrorPartiallyProcessed;
 pub type SvgE = SVGProcessingError;
 pub type SpE = SpecError;
index 53b69871562bbaed27e478020fd32272d8f012f7..5a9a80ffc712eb969a6d3b9f26e397e08cc1ba5a 100644 (file)
@@ -611,7 +611,7 @@ impl<'r> PrepareUpdatesBuffer<'r> {
   }
 
   pub fn piece_report_error(ig: &mut Instance,
-                            error: PieceOpError, piece: PieceId,
+                            error: Inapplicable, piece: PieceId,
                             logents: Vec<LogEntry>,
                             partially: PieceOpErrorPartiallyProcessed,
                             client: ClientId, cseq: ClientSequence)