//! Error types for the object detector use thiserror::Error; /// Errors that can occur in the object detector #[derive(Debug, Error)] pub enum DetectorError { /// Invalid image data #[error("Invalid image data: {0}")] InvalidImage(String), /// Model not initialized #[error("Model not initialized")] NotInitialized, /// Invalid configuration #[error("Invalid configuration: {0}")] InvalidConfig(String), /// Detection failed #[error("Detection failed: {0}")] DetectionFailed(String), /// Serialization error #[error("Serialization error: {0}")] SerializationError(#[from] serde_json::Error), } pub type Result = std::result::Result; #[cfg(test)] mod tests { use super::*; #[test] fn test_error_invalid_image() { let err = DetectorError::InvalidImage("bad data".to_string()); assert_eq!(err.to_string(), "Invalid image data: bad data"); } #[test] fn test_error_not_initialized() { let err = DetectorError::NotInitialized; assert_eq!(err.to_string(), "Model not initialized"); } #[test] fn test_error_invalid_config() { let err = DetectorError::InvalidConfig("bad threshold".to_string()); assert_eq!(err.to_string(), "Invalid configuration: bad threshold"); } #[test] fn test_error_detection_failed() { let err = DetectorError::DetectionFailed("inference error".to_string()); assert_eq!(err.to_string(), "Detection failed: inference error"); } #[test] fn test_error_from_serde() { let json_err = serde_json::from_str::("not a number").unwrap_err(); let err = DetectorError::from(json_err); assert!(err.to_string().contains("Serialization error")); } }