1use thiserror::Error;
2
3#[derive(Error, Debug)]
4pub enum PathwiseError {
5 #[error("invalid SDE parameters: {0}")]
6 InvalidParameters(String),
7
8 #[error("numerical divergence at step {step}: value={value}")]
9 NumericalDivergence { step: usize, value: f64 },
10
11 #[error("inference failed to converge: {0}")]
12 ConvergenceFailure(String),
13
14 #[error("Feller condition violated: {0}")]
17 FellerViolation(String),
18
19 #[error("dimension mismatch: {0}")]
21 DimensionMismatch(String),
22}
23
24#[cfg(test)]
25mod tests {
26 use super::*;
27
28 #[test]
29 fn error_messages_are_human_readable() {
30 let e = PathwiseError::InvalidParameters("H must be in (0,1)".into());
31 assert!(e.to_string().contains("H must be in (0,1)"));
32 let e = PathwiseError::FellerViolation("2*1*0.02 <= 0.04".into());
33 assert!(e.to_string().contains("Feller"));
34 let e = PathwiseError::DimensionMismatch("expected 2x2, got 3x3".into());
35 assert!(e.to_string().contains("dimension mismatch"));
36 }
37}