ricecoder_images/
error.rs

1//! Error types for image operations.
2
3use thiserror::Error;
4
5/// Result type for image operations.
6pub type ImageResult<T> = Result<T, ImageError>;
7
8/// Errors that can occur during image operations.
9#[derive(Debug, Error)]
10pub enum ImageError {
11    /// Image format is not supported.
12    #[error("Format not supported: {0}. Supported formats: PNG, JPG, GIF, WebP")]
13    FormatNotSupported(String),
14
15    /// Image file exceeds maximum size (10 MB).
16    #[error("File too large: {size_mb:.1} MB exceeds maximum of 10 MB")]
17    FileTooLarge { size_mb: f64 },
18
19    /// File is not a valid image.
20    #[error("Invalid image file: {0}")]
21    InvalidFile(String),
22
23    /// Image analysis failed.
24    #[error("Analysis failed: {0}")]
25    AnalysisFailed(String),
26
27    /// Cache operation failed.
28    #[error("Cache error: {0}")]
29    CacheError(String),
30
31    /// Display operation failed.
32    #[error("Display error: {0}")]
33    DisplayError(String),
34
35    /// I/O error.
36    #[error("I/O error: {0}")]
37    IoError(#[from] std::io::Error),
38
39    /// Path traversal attempt detected.
40    #[error("Invalid file path: path traversal detected")]
41    PathTraversalError,
42
43    /// Configuration error.
44    #[error("Configuration error: {0}")]
45    ConfigError(String),
46
47    /// Serialization error.
48    #[error("Serialization error: {0}")]
49    SerializationError(String),
50}
51
52impl From<serde_yaml::Error> for ImageError {
53    fn from(err: serde_yaml::Error) -> Self {
54        ImageError::ConfigError(err.to_string())
55    }
56}
57
58impl From<serde_json::Error> for ImageError {
59    fn from(err: serde_json::Error) -> Self {
60        ImageError::SerializationError(err.to_string())
61    }
62}