Skip to main content

fdars_core/
error.rs

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