Skip to main content

fdars_core/
error.rs

1use std::fmt;
2
3/// Error type for fdars operations.
4#[derive(Debug, Clone, PartialEq)]
5#[non_exhaustive]
6pub enum FdarError {
7    /// Input dimensions invalid (empty matrix, length mismatch).
8    InvalidDimension {
9        parameter: &'static str,
10        expected: String,
11        actual: String,
12    },
13    /// Parameter value out of allowed range.
14    InvalidParameter {
15        parameter: &'static str,
16        message: String,
17    },
18    /// Numerical computation failed (SVD, matrix inversion, convergence).
19    ComputationFailed {
20        operation: &'static str,
21        detail: String,
22    },
23    /// Enum conversion from integer failed.
24    InvalidEnumValue { enum_name: &'static str, value: i32 },
25}
26
27impl fmt::Display for FdarError {
28    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29        match self {
30            FdarError::InvalidDimension {
31                parameter,
32                expected,
33                actual,
34            } => write!(
35                f,
36                "invalid dimension for '{parameter}': expected {expected}, got {actual}"
37            ),
38            FdarError::InvalidParameter { parameter, message } => {
39                write!(f, "invalid parameter '{parameter}': {message}")
40            }
41            FdarError::ComputationFailed { operation, detail } => {
42                write!(f, "{operation} failed: {detail}")
43            }
44            FdarError::InvalidEnumValue { enum_name, value } => {
45                write!(f, "invalid value {value} for enum '{enum_name}'")
46            }
47        }
48    }
49}
50
51impl std::error::Error for FdarError {}