Skip to main content

nereids_fitting/
error.rs

1//! Error types for the nereids-fitting crate.
2
3use std::fmt;
4
5/// Errors from fitting operations (input validation).
6#[derive(Debug)]
7pub enum FittingError {
8    /// Observed data is empty.
9    EmptyData,
10    /// Array length mismatch.
11    LengthMismatch {
12        /// Expected length.
13        expected: usize,
14        /// Actual length.
15        actual: usize,
16        /// Name of the mismatched field.
17        field: &'static str,
18    },
19    /// Invalid model configuration.
20    InvalidConfig(String),
21    /// Model evaluation failed (e.g. broadening error, invalid physics state).
22    EvaluationFailed(String),
23}
24
25impl fmt::Display for FittingError {
26    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27        match self {
28            Self::EmptyData => write!(f, "observed data must not be empty"),
29            Self::LengthMismatch {
30                expected,
31                actual,
32                field,
33            } => write!(
34                f,
35                "{field} length ({actual}) must match expected length ({expected})"
36            ),
37            Self::InvalidConfig(msg) => write!(f, "invalid model configuration: {msg}"),
38            Self::EvaluationFailed(msg) => write!(f, "model evaluation failed: {msg}"),
39        }
40    }
41}
42
43impl std::error::Error for FittingError {}