chiark / gitweb /
Make UnsupportedColourSpec its own type
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 29 Mar 2021 20:34:46 +0000 (21:34 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 29 Mar 2021 20:34:46 +0000 (21:34 +0100)
We're going to want it for LibraryLoadError too.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/cmdlistener.rs
src/error.rs
src/spec.rs

index 27b1e377bd60f0d49da2539ba00d3d4e7dc5617a..bc6c5603ecd7acd0f7a589a227dde26570bd660b 100644 (file)
@@ -359,7 +359,7 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>(
 
     MGI::SetTableColour(colour) => {
       let ig = cs.check_acl(ag, ig, PCH::Instance, &[TP::ChangePieces])?.0;
-      let colour: Colour = (&colour).try_into()?;
+      let colour: Colour = (&colour).try_into().map_err(|e| SpE::from(e))?;
       ig.gs.table_colour = colour.clone();
       (U{ pcs: vec![],
           log: vec![ LogEntry {
index 365c7ed00ed5a511a8813cb0e8e2160c22d48845..20f2fc78810a2523983907ee245a836f09648e88 100644 (file)
@@ -65,6 +65,10 @@ pub enum InternalError {
   Aggregated,
 }
 
+#[derive(Error,Copy,Clone,Debug,Serialize,Deserialize)]
+#[error("Unsupported colour spec")]
+pub struct UnsupportedColourSpec;
+
 #[derive(Error)]
 pub struct InternalLogicError {
   desc: Cow<'static, str>,
index 58125f7706fcc3ad512e6f9157c45d7f5c35d372..5e5d5dbdbc0adb70088af2a06d00df030e6949df 100644 (file)
@@ -24,6 +24,7 @@ use otter_base::geometry::{Coord,Pos};
 use otter_base::misc::display_as_debug;
 
 use crate::accounts::AccountName;
+use crate::error::UnsupportedColourSpec;
 use crate::gamestate::PieceSpec;
 use crate::prelude::default;
 
@@ -59,7 +60,7 @@ pub struct UrlSpec(pub String);
 #[derive(Error,Clone,Serialize,Deserialize,Debug)]
 pub enum SpecError {
   ImproperSizeSpec,
-  UnsupportedColourSpec,
+  UnsupportedColourSpec(#[from] UnsupportedColourSpec),
   FaceNotFound,
   InternalError(String),
   PosOffTable,
@@ -534,8 +535,8 @@ pub mod implementation {
   }
 
   impl TryFrom<&ColourSpec> for Colour {
-    type Error = SpecError;
-    #[throws(SpecError)]
+    type Error = UnsupportedColourSpec;
+    #[throws(UnsupportedColourSpec)]
     fn try_from(spec: &ColourSpec) -> Colour {
       lazy_static! {
         static ref RE: Regex = Regex::new(concat!(
@@ -547,7 +548,7 @@ pub mod implementation {
       }
       let s = &spec.0;
       if !RE.is_match(s) {
-        throw!(SpecError::UnsupportedColourSpec);
+        throw!(UnsupportedColourSpec);
       }
       Html(spec.0.clone())
     }