Skip to main content

spectral_prosody/
error.rs

1use std::fmt;
2
3/// Errors that can occur during spectral prosody analysis.
4#[derive(Debug, Clone)]
5pub enum ProsodyError {
6    /// Not enough nodes to construct a graph.
7    InsufficientNodes { got: usize, need: usize },
8    /// Eigen-decomposition failed to converge.
9    DecompositionFailed(String),
10    /// Invalid parameter value.
11    InvalidParameter(String),
12    /// Empty feature vector.
13    EmptyFeature,
14    /// Index out of range.
15    IndexOutOfRange { index: usize, len: usize },
16}
17
18impl fmt::Display for ProsodyError {
19    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
20        match self {
21            Self::InsufficientNodes { got, need } => {
22                write!(f, "need at least {need} nodes, got {got}")
23            }
24            Self::DecompositionFailed(msg) => write!(f, "decomposition failed: {msg}"),
25            Self::InvalidParameter(msg) => write!(f, "invalid parameter: {msg}"),
26            Self::EmptyFeature => write!(f, "feature vector is empty"),
27            Self::IndexOutOfRange { index, len } => {
28                write!(f, "index {index} out of range (len={len})")
29            }
30        }
31    }
32}
33
34impl std::error::Error for ProsodyError {}