use std::path::PathBuf;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error("failed to load model from {path}: {source}")]
LoadModel {
path: PathBuf,
source: ort::Error,
},
#[error(transparent)]
Ort(#[from] ort::Error),
#[error("failed to read CMVN file from {path}: {source}")]
LoadCmvn {
path: PathBuf,
source: std::io::Error,
},
#[error("invalid CMVN format: {reason}")]
InvalidCmvn {
reason: &'static str,
},
#[error("ONNX output {tensor} had unexpected shape {shape:?}")]
UnexpectedOutputShape {
tensor: &'static str,
shape: Vec<i64>,
},
}
pub type Result<T> = std::result::Result<T, Error>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn invalid_cmvn_carries_static_reason() {
let err = Error::InvalidCmvn {
reason: "missing magic",
};
assert!(err.to_string().contains("missing magic"));
}
#[test]
fn unexpected_output_shape_renders_shape() {
let err = Error::UnexpectedOutputShape {
tensor: "probs",
shape: vec![1, 2, 3],
};
assert!(err.to_string().contains("probs"));
assert!(err.to_string().contains("[1, 2, 3]"));
}
}