hpr_motor/error.rs
1//! Error types for the motor model, its file formats and the catalog.
2
3use thiserror::Error;
4
5/// An error from the motor crate: a value outside a model's domain, a thrust curve or motor that
6/// can't be built, or a motor file that can't be read.
7#[derive(Debug, Clone, PartialEq, Error)]
8#[non_exhaustive]
9pub enum MotorError {
10 /// An input outside a model's domain, such as a negative mass or a non-finite time.
11 #[error("{what} is outside its domain: {value}")]
12 Domain {
13 /// What the value is.
14 what: &'static str,
15 /// The offending value.
16 value: f64,
17 },
18 /// Text that doesn't parse as the value it should hold.
19 #[error("can't read {what} from {text:?}")]
20 Parse {
21 /// What the text should hold.
22 what: &'static str,
23 /// The text.
24 text: String,
25 },
26 /// A thrust curve needs positive total impulse and a positive NFPA 1125 burn time.
27 #[error("a thrust curve needs positive total impulse and burn time")]
28 NoThrust,
29 /// Thrust-curve times must not decrease.
30 #[error("thrust-curve times must not decrease; sample {index} at {time_s} s is earlier")]
31 TimesDecreasing {
32 /// Index of the first sample whose time is before its predecessor's.
33 index: usize,
34 /// Its time, s.
35 time_s: f64,
36 },
37 /// A motor file is malformed.
38 #[error("{format} line {line}: {message}")]
39 Syntax {
40 /// The file format (`.eng` or `.rse`).
41 format: &'static str,
42 /// The 1-based line number.
43 line: usize,
44 /// What is wrong.
45 message: String,
46 },
47 /// A motor catalog index that doesn't deserialize.
48 #[error("invalid motor catalog index: {0}")]
49 Catalog(String),
50 /// Masses or geometry that contradict each other, such as a propellant mass above the total
51 /// mass, or grains that don't fit.
52 #[error("inconsistent motor: {0}")]
53 Inconsistent(String),
54}