1use std::path::PathBuf;
2use thiserror::Error;
3
4#[derive(Debug, Error)]
5pub enum CompressionError {
6 #[error("I/O error: {0}")]
7 Io(#[from] std::io::Error),
8
9 #[error("Image processing error: {0}")]
10 ImageProcessing(#[from] image::ImageError),
11
12 #[error("PNG optimization error: {0}")]
13 PngOptimization(String),
14
15 #[error("Invalid quality value: {0}. Must be between 1 and 100")]
16 InvalidQuality(u8),
17
18 #[error("Invalid image dimensions: {0}x{1}. Maximum allowed: {2}x{2}")]
19 InvalidDimensions(u32, u32, u32),
20
21 #[error("File too large: {0} bytes. Maximum allowed: {1} bytes")]
22 FileTooLarge(u64, u64),
23
24 #[error("Unsupported format: {0}")]
25 UnsupportedFormat(String),
26
27 #[error("File not found: {0}")]
28 FileNotFound(PathBuf),
29
30 #[error("Failed to create output directory: {0}")]
31 DirectoryCreationFailed(PathBuf),
32
33 #[error("No image files found in input path: {0}")]
34 NoImageFilesFound(String),
35
36 #[error("Walkdir error: {0}")]
37 WalkdirError(#[from] walkdir::Error),
38
39 #[error("Walrus upload error: {0}")]
40 WalrusUpload(String),
41
42 #[error("Batch memory limit exceeded: estimated {0}MiB, maximum allowed {1}MiB")]
43 BatchMemoryLimitExceeded(u64, u64),
44
45 #[error("Batch file count limit exceeded: {0} files, maximum allowed {1}")]
46 BatchFileLimitExceeded(usize, usize),
47
48 #[error(
49 "Insufficient available memory: estimated batch requires {0}MiB, but only {1}MiB available"
50 )]
51 InsufficientMemory(u64, u64),
52}
53
54pub type Result<T> = std::result::Result<T, CompressionError>;