1use crate::cancel::Cancelled;
5use crate::cutter::CutterError;
6use crate::model::TransformError;
7use crate::numeric::NumericError;
8
9#[derive(Clone, Debug, PartialEq)]
10pub enum CamError {
11 Cancelled,
13 Cutter(CutterError),
15 Numeric(NumericError),
17 Transform(TransformError),
19 NonFinite { what: String },
21 EmptyTarget { operation_id: String },
23 UnresolvedTarget { solid: String, face: Option<String> },
25 UnsupportedCutter { strategy: String, cutter: String },
27 InvalidInput(String),
29}
30
31impl std::fmt::Display for CamError {
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 match self {
34 CamError::Cancelled => write!(f, "cancelled"),
35 CamError::Cutter(e) => write!(f, "cutter: {e}"),
36 CamError::Numeric(e) => write!(f, "tolerance: {e}"),
37 CamError::Transform(e) => write!(f, "setup transform: {e}"),
38 CamError::NonFinite { what } => write!(f, "{what} is not finite"),
39 CamError::EmptyTarget { operation_id } => {
40 write!(f, "operation {operation_id} has no target triangles")
41 }
42 CamError::UnresolvedTarget { solid, face: None } => {
43 write!(f, "target body {solid:?} is not in the mesh snapshot")
44 }
45 CamError::UnresolvedTarget { solid, face: Some(face) } => {
46 write!(f, "target face {face:?} of body {solid:?} is not in the mesh snapshot")
47 }
48 CamError::UnsupportedCutter { strategy, cutter } => {
49 write!(f, "strategy {strategy} does not support a {cutter} cutter")
50 }
51 CamError::InvalidInput(msg) => write!(f, "{msg}"),
52 }
53 }
54}
55
56impl std::error::Error for CamError {}
57
58impl From<Cancelled> for CamError {
59 fn from(_: Cancelled) -> Self {
60 CamError::Cancelled
61 }
62}
63
64impl From<CutterError> for CamError {
65 fn from(e: CutterError) -> Self {
66 CamError::Cutter(e)
67 }
68}
69
70impl From<NumericError> for CamError {
71 fn from(e: NumericError) -> Self {
72 CamError::Numeric(e)
73 }
74}
75
76impl From<TransformError> for CamError {
77 fn from(e: TransformError) -> Self {
78 CamError::Transform(e)
79 }
80}