Skip to main content

iris/
error.rs

1use thiserror::Error;
2
3/// Error type for all Iris library operations.
4#[derive(Debug, Error)]
5pub enum IrisError {
6    #[error("Image I/O or format error: {0}")]
7    Image(#[from] image::ImageError),
8
9    #[error("Standard I/O error: {0}")]
10    Io(#[from] std::io::Error),
11
12    #[error("Tensor operation failed: {0}")]
13    Tensor(String),
14
15    #[error("Dimension mismatch: expected {expected:?}, found {actual:?}")]
16    DimensionMismatch {
17        expected: Vec<usize>,
18        actual: Vec<usize>,
19    },
20
21    #[error("Invalid parameter: {0}")]
22    InvalidParameter(String),
23
24    #[error("Model load failure: {0}")]
25    ModelLoad(String),
26
27    #[error("Model execution or inference failure: {0}")]
28    Inference(String),
29
30    #[error("Feature not implemented: {0}")]
31    FeatureNotImplemented(String),
32
33    #[error("Generic error: {0}")]
34    Generic(String),
35
36    #[error("Video error: {0}")]
37    Video(String),
38}
39
40/// Result type for Iris library operations.
41pub type Result<T> = std::result::Result<T, IrisError>;
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_error_formatting() {
49        let err = IrisError::Generic("test error".to_string());
50        assert_eq!(format!("{}", err), "Generic error: test error");
51
52        let err_dim = IrisError::DimensionMismatch {
53            expected: vec![1, 2, 3],
54            actual: vec![1, 2],
55        };
56        assert!(format!("{}", err_dim).contains("Dimension mismatch"));
57    }
58}