1use core::fmt;
8use numra_core::NumraError;
9
10#[derive(Clone, Debug, PartialEq)]
12pub enum SignalError {
13 InvalidOrder(usize),
15 InvalidCutoff { cutoff: f64, nyquist: f64 },
17 InvalidRipple(f64),
19 InsufficientData { need: usize, got: usize },
21 InvalidParameter(String),
23}
24
25impl fmt::Display for SignalError {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 match self {
28 Self::InvalidOrder(n) => write!(f, "invalid filter order: {n}"),
29 Self::InvalidCutoff { cutoff, nyquist } => {
30 write!(f, "cutoff {cutoff} must be in (0, {nyquist})")
31 }
32 Self::InvalidRipple(r) => write!(f, "ripple must be positive, got {r}"),
33 Self::InsufficientData { need, got } => {
34 write!(f, "need at least {need} samples, got {got}")
35 }
36 Self::InvalidParameter(msg) => write!(f, "invalid parameter: {msg}"),
37 }
38 }
39}
40
41impl std::error::Error for SignalError {}
42
43impl From<SignalError> for NumraError {
44 fn from(e: SignalError) -> Self {
45 NumraError::Signal(e.to_string())
46 }
47}