From: Ian Jackson Date: Mon, 29 Mar 2021 20:34:46 +0000 (+0100) Subject: Make UnsupportedColourSpec its own type X-Git-Tag: otter-0.5.0~383 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=20e2e237813ad561cef99e5df70742aec01a07b4;p=otter.git Make UnsupportedColourSpec its own type We're going to want it for LibraryLoadError too. Signed-off-by: Ian Jackson --- diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 27b1e377..bc6c5603 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -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 { diff --git a/src/error.rs b/src/error.rs index 365c7ed0..20f2fc78 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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>, diff --git a/src/spec.rs b/src/spec.rs index 58125f77..5e5d5dbd 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -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()) }