Skip to main content

rockets_engine/
error.rs

1use std::fmt;
2
3/// Checked construction, integration and user-supplied model errors.
4#[derive(Debug, Clone, PartialEq)]
5pub enum Error {
6    /// A configuration, state or command violates the public input contract.
7    InvalidInput {
8        /// Invalid field or group of fields.
9        field: &'static str,
10        /// Description of the required invariant.
11        reason: &'static str,
12    },
13    /// The requested duration exceeds the configured internal work budget.
14    StepLimitExceeded {
15        /// Maximum permitted RK4 substeps per call.
16        limit: usize,
17    },
18    /// Numerical overflow, non-finite model output or inability to advance time.
19    NumericalFailure(&'static str),
20    /// An error reported by an environmental model or guidance implementation.
21    Model(String),
22}
23
24impl Error {
25    pub(crate) fn invalid(field: &'static str, reason: &'static str) -> Self {
26        Self::InvalidInput { field, reason }
27    }
28}
29
30impl fmt::Display for Error {
31    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
32        match self {
33            Self::InvalidInput { field, reason } => write!(f, "{field}: {reason}"),
34            Self::StepLimitExceeded { limit } => write!(f, "integration exceeded {limit} substeps"),
35            Self::NumericalFailure(reason) => write!(f, "integration failed: {reason}"),
36            Self::Model(message) => write!(f, "model failed: {message}"),
37        }
38    }
39}
40
41impl std::error::Error for Error {}
42
43/// Result type shared by the solver and extension hooks.
44pub type Result<T> = std::result::Result<T, Error>;