ricecoder_images/
error.rs1use thiserror::Error;
4
5pub type ImageResult<T> = Result<T, ImageError>;
7
8#[derive(Debug, Error)]
10pub enum ImageError {
11 #[error("Format not supported: {0}. Supported formats: PNG, JPG, GIF, WebP")]
13 FormatNotSupported(String),
14
15 #[error("File too large: {size_mb:.1} MB exceeds maximum of 10 MB")]
17 FileTooLarge { size_mb: f64 },
18
19 #[error("Invalid image file: {0}")]
21 InvalidFile(String),
22
23 #[error("Analysis failed: {0}")]
25 AnalysisFailed(String),
26
27 #[error("Cache error: {0}")]
29 CacheError(String),
30
31 #[error("Display error: {0}")]
33 DisplayError(String),
34
35 #[error("I/O error: {0}")]
37 IoError(#[from] std::io::Error),
38
39 #[error("Invalid file path: path traversal detected")]
41 PathTraversalError,
42
43 #[error("Configuration error: {0}")]
45 ConfigError(String),
46
47 #[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}