From 87108beea517903a92ee5ee805666e5397d15b53 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 12 Apr 2022 21:33:51 +0100 Subject: [PATCH] spec errors: Expand WrongNumberOfFaces error We're going to want to reuse this in a new context. And, this already produces better error messages for the case where it's used now. It seems better to provide this rather generic error rather than expect each funky piece kind to invent its own kind in SpecError. Signed-off-by: Ian Jackson --- src/deck.rs | 7 ++++++- src/spec.rs | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/deck.rs b/src/deck.rs index 55fe7ca3..e5eae521 100644 --- a/src/deck.rs +++ b/src/deck.rs @@ -55,7 +55,12 @@ impl PieceSpec for piece_specs::Deck { "magic-pickupdeck", &common)?; if shape.count_faces() != 2 { - throw!(SpE::WrongNumberOfFaces); + throw!(SpE::WrongNumberOfFaces { + got: shape.count_faces(), + got_why: "shape".into(), + exp: 2, + exp_why: "required".into(), + }); } gpc.moveable = PieceMoveable::IfWresting; gpc.rotateable = false; diff --git a/src/spec.rs b/src/spec.rs index 162a72f6..4e2e7db6 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -6,6 +6,7 @@ use crate::imports::*; +use std::borrow::Cow; use std::collections::hash_map::HashMap; use std::collections::hash_set::HashSet; use std::fmt::Debug; @@ -74,7 +75,6 @@ pub enum SpecError { #[error("compass angle invalid")] CompassAngleInvalid, #[error("piece has zero faces")] ZeroFaces, #[error("inconsistent face/edge colours")] InconsistentFacesEdgecoloursCount, - #[error("wrong number of faces")] WrongNumberOfFaces, #[error("specified with of edges, but no edges")] SpecifiedWidthOfNoEdges, #[error("shape not supported")] UnsupportedShape, #[error("negative timeout")] NegativeTimeout, @@ -82,6 +82,13 @@ pub enum SpecError { #[error("piece alias not found")] AliasNotFound, #[error("piece alias target is multi spec")] AliasTargetMultiSpec, #[error("piece alias loop")] AliasLoop(String), + #[error("wrong number of faces {got_why}={got} != {exp_why}={exp}")] + WrongNumberOfFaces { + got: RawFaceId, + exp: RawFaceId, + got_why: Cow<'static, str>, + exp_why: Cow<'static, str>, + } } //---------- Bundle "otter.toml" file ---------- -- 2.30.2