hpr_design/error.rs
1//! Error types for the design model.
2
3use hpr_core::CoreError;
4use thiserror::Error;
5
6/// An error from the design model: a dimension outside its domain, geometry that contradicts
7/// itself, or mass properties no real body could have.
8#[derive(Debug, Clone, PartialEq, Error)]
9#[non_exhaustive]
10pub enum DesignError {
11 /// An input outside its domain, such as a negative length.
12 #[error("{what} is outside its domain: {value}")]
13 Domain {
14 /// What the value is.
15 what: &'static str,
16 /// The offending value.
17 value: f64,
18 },
19 /// Dimensions that contradict each other, such as a wall thicker than the radius.
20 #[error("inconsistent geometry: {0}")]
21 Geometry(String),
22 /// An inertia tensor that no real body has.
23 #[error("unphysical inertia: {0}")]
24 UnphysicalInertia(String),
25 /// A material of the wrong kind for the part, such as a surface density for a solid.
26 #[error("{part} needs a {expected} material, but {material} is a {actual} material")]
27 MaterialKind {
28 /// The part.
29 part: &'static str,
30 /// The material's name.
31 material: String,
32 /// The kind the part needs.
33 expected: &'static str,
34 /// The material's kind.
35 actual: &'static str,
36 },
37 /// A design tree that doesn't hold together, such as fins attached to an inner tube or an
38 /// automatic radius with nothing to take it from.
39 #[error("{id}: {message}")]
40 Tree {
41 /// The id of the stage, component or configuration at fault.
42 id: String,
43 /// What is wrong.
44 message: String,
45 },
46 /// An error in one stage or component, with its id.
47 #[error("{id}: {source}")]
48 InComponent {
49 /// The id of the stage or component.
50 id: String,
51 /// The error.
52 source: Box<DesignError>,
53 },
54 /// Two stages, components or configurations share an id, or an id is empty.
55 #[error("ids must be unique and non-empty, but `{0}` is not")]
56 DuplicateId(String),
57 /// A reference to an id that doesn't exist.
58 #[error("no {what} has the id `{id}`")]
59 UnknownId {
60 /// What was looked for.
61 what: &'static str,
62 /// The id.
63 id: String,
64 },
65 /// A numerical method failed, such as an integral that didn't converge.
66 #[error(transparent)]
67 Numerics(#[from] CoreError),
68}