Skip to main content

hpr_analysis/
error.rs

1//! Errors of the analysis tools.
2
3use hpr_design::DesignError;
4use hpr_motor::MotorError;
5use hpr_sim::SimError;
6
7/// What an analysis refuses or can't do.
8#[derive(Debug, thiserror::Error)]
9#[non_exhaustive]
10pub enum AnalysisError {
11    /// A number outside the range it is defined on.
12    #[error("{what} out of range: {value}")]
13    Domain {
14        /// What the number is.
15        what: &'static str,
16        /// The number.
17        value: f64,
18    },
19    /// A count larger than it can be.
20    #[error("{what}: {count} is more than {limit}")]
21    Count {
22        /// What is counted.
23        what: &'static str,
24        /// The count.
25        count: usize,
26        /// Its limit.
27        limit: usize,
28    },
29    /// Too few of something for what was asked.
30    #[error("{what}: {count} given, at least {minimum} needed")]
31    TooFew {
32        /// What is counted.
33        what: &'static str,
34        /// The count.
35        count: usize,
36        /// The fewest that will do.
37        minimum: usize,
38    },
39    /// A list of the wrong length.
40    #[error("{what}: {length} given, {expected} expected")]
41    Length {
42        /// What the list is, and what it is counted against.
43        what: &'static str,
44        /// Its length.
45        length: usize,
46        /// The length it should have.
47        expected: usize,
48    },
49    /// A model's output that can't be used: one that isn't finite at the given point of a
50    /// sensitivity design, or a NaN or `−∞` at the given evaluation of an optimizer's run, both
51    /// counted from 0.
52    #[error("the output at point {index} is not finite: {value}")]
53    Output {
54        /// The point's index in the design's order.
55        index: usize,
56        /// The output.
57        value: f64,
58    },
59    /// Two sensitivity factors with one name, which would make their results ambiguous.
60    #[error("two factors named {0:?}")]
61    DuplicateFactor(String),
62    /// Two optimization variables with one name, which would make the result ambiguous.
63    #[error("two variables named {0:?}")]
64    DuplicateVariable(String),
65    /// A first candidate of an optimizer that didn't fall inside the variables' bounds in the
66    /// draws allowed: the steps are too large for the bounds, or the starts too close to them.
67    #[error("no candidate inside the variables' bounds in {draws} draws")]
68    OutOfBounds {
69        /// How many draws were made.
70        draws: usize,
71    },
72    /// A rocket configuration the design doesn't have.
73    #[error("no configuration {0:?} in the design")]
74    NoConfiguration(String),
75    /// Something the analysis has no model for.
76    #[error("unsupported: {0}")]
77    Unsupported(String),
78    /// From the design.
79    #[error(transparent)]
80    Design(#[from] DesignError),
81    /// From a motor.
82    #[error(transparent)]
83    Motor(#[from] MotorError),
84    /// From a flight.
85    #[error(transparent)]
86    Sim(#[from] SimError),
87}