1use std::path::PathBuf;
4
5#[derive(Debug, thiserror::Error)]
7#[non_exhaustive]
8pub enum Error {
9 #[error("failed to load model from {path}: {source}")]
11 LoadModel {
12 path: PathBuf,
14 source: ort::Error,
16 },
17
18 #[error(transparent)]
20 Ort(#[from] ort::Error),
21
22 #[error("failed to read CMVN file from {path}: {source}")]
24 LoadCmvn {
25 path: PathBuf,
27 source: std::io::Error,
29 },
30
31 #[error("invalid CMVN format: {reason}")]
33 InvalidCmvn {
34 reason: &'static str,
36 },
37
38 #[error("ONNX output {tensor} had unexpected shape {shape:?}")]
40 UnexpectedOutputShape {
41 tensor: &'static str,
43 shape: Vec<i64>,
45 },
46}
47
48pub type Result<T> = std::result::Result<T, Error>;
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn invalid_cmvn_carries_static_reason() {
57 let err = Error::InvalidCmvn {
58 reason: "missing magic",
59 };
60 assert!(err.to_string().contains("missing magic"));
61 }
62
63 #[test]
64 fn unexpected_output_shape_renders_shape() {
65 let err = Error::UnexpectedOutputShape {
66 tensor: "probs",
67 shape: vec![1, 2, 3],
68 };
69 assert!(err.to_string().contains("probs"));
70 assert!(err.to_string().contains("[1, 2, 3]"));
71 }
72}