//! Error types for the rtx-vision crate use thiserror::Error; /// Result type for vision operations pub type Result = std::result::Result; /// Vision-specific error types #[derive(Debug, Error)] pub enum VisionError { /// Tensor operation failed #[error("Tensor operation failed: {0}")] Tensor(#[from] rtx_tensor::TensorError), /// Computation operation failed #[error("Computation failed: {0}")] Computation(String), /// Shape-related error #[error("Shape error: {0}")] Shape(String), /// Initialization error #[error("Initialization failed: {0}")] Initialization(String), /// Autograd operation failed #[error("Autograd operation failed: {0}")] Autograd(String), /// Image processing error #[error("Image processing error: {0}")] ImageError(#[from] image::ImageError), /// Invalid image dimensions #[error("Invalid image dimensions: expected {expected}, got {got}")] InvalidDimensions { expected: String, got: String }, /// Invalid patch size #[error("Invalid patch size: {size} for image of size {width}x{height}")] InvalidPatchSize { size: usize, width: usize, height: usize, }, /// Invalid model configuration #[error("Invalid model configuration: {0}")] InvalidConfig(String), /// Unsupported operation #[error("Unsupported operation: {0}")] UnsupportedOperation(String), /// Shape mismatch #[error("Shape mismatch: expected {expected:?}, got {got:?}")] ShapeMismatch { expected: Vec, got: Vec, }, /// Invalid number of channels #[error("Invalid number of channels: expected {expected}, got {got}")] InvalidChannels { expected: usize, got: usize }, /// IO error #[error("IO error: {0}")] IoError(#[from] std::io::Error), /// Generic error with context #[error("{0}")] Other(String), /// Invalid tensor shape (legacy) #[error("Invalid shape: {0}")] InvalidShape(String), /// Tensor operation failed (legacy) #[error("Tensor error: {0}")] TensorError(String), } // Add convenience constructors for common error types impl VisionError { /// Create a computation error pub fn computation>(msg: S) -> Self { VisionError::Computation(msg.into()) } /// Create a shape error pub fn shape>(msg: S) -> Self { VisionError::Shape(msg.into()) } /// Create an initialization error pub fn initialization>(msg: S) -> Self { VisionError::Initialization(msg.into()) } /// Create an autograd error pub fn autograd>(msg: S) -> Self { VisionError::Autograd(msg.into()) } } // TensorError From conversion handled by #[from] attribute in enum definition impl From for VisionError { fn from(err: anyhow::Error) -> Self { VisionError::Other(err.to_string()) } }