1use std::fmt;
4
5#[derive(Debug)]
7pub enum FittingError {
8 EmptyData,
10 LengthMismatch {
12 expected: usize,
14 actual: usize,
16 field: &'static str,
18 },
19 InvalidConfig(String),
21 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 {}