1use thiserror::Error;
2
3#[derive(Debug, Clone, Error)]
5pub enum IoError {
6 #[error("S3 error: {0}")]
8 S3(String),
9
10 #[error("Range out of bounds: requested {requested} bytes at offset {offset}, size is {size}")]
12 RangeOutOfBounds {
13 offset: u64,
14 requested: u64,
15 size: u64,
16 },
17
18 #[error("Connection error: {0}")]
20 Connection(String),
21
22 #[error("Object not found: {0}")]
24 NotFound(String),
25}
26
27#[derive(Debug, Clone, Error)]
29pub enum FormatError {
30 #[error("I/O error: {0}")]
32 Io(#[from] IoError),
33
34 #[error("TIFF error: {0}")]
36 Tiff(#[from] TiffError),
37
38 #[error("Unsupported format: {reason}")]
40 UnsupportedFormat { reason: String },
41}
42
43#[derive(Debug, Clone, Error)]
45pub enum TiffError {
46 #[error("I/O error: {0}")]
48 Io(#[from] IoError),
49
50 #[error("Invalid TIFF magic bytes: expected 0x4949 (II) or 0x4D4D (MM), got 0x{0:04X}")]
52 InvalidMagic(u16),
53
54 #[error("Invalid TIFF version: expected 42 (TIFF) or 43 (BigTIFF), got {0}")]
56 InvalidVersion(u16),
57
58 #[error("Invalid BigTIFF offset byte size: expected 8, got {0}")]
60 InvalidBigTiffOffsetSize(u16),
61
62 #[error("File too small: need at least {required} bytes, got {actual}")]
64 FileTooSmall { required: u64, actual: u64 },
65
66 #[error("Invalid IFD offset: {0}")]
68 InvalidIfdOffset(u64),
69
70 #[error("Missing required tag: {0}")]
72 MissingTag(&'static str),
73
74 #[error("Invalid tag value for {tag}: {message}")]
76 InvalidTagValue { tag: &'static str, message: String },
77
78 #[error("Unsupported compression: {0} (only JPEG and JPEG 2000 are supported)")]
80 UnsupportedCompression(String),
81
82 #[error("Unsupported organization: file uses strips instead of tiles")]
84 StripOrganization,
85
86 #[error("Unknown field type: {0}")]
88 UnknownFieldType(u16),
89}
90
91#[derive(Debug, Clone, Error)]
93pub enum TileError {
94 #[error("I/O error: {0}")]
96 Io(#[from] IoError),
97
98 #[error("Slide error: {0}")]
100 Slide(#[from] TiffError),
101
102 #[error("Failed to decode JPEG: {message}")]
104 DecodeError { message: String },
105
106 #[error("Failed to encode JPEG: {message}")]
108 EncodeError { message: String },
109
110 #[error("Invalid level: {level} (slide has {max_levels} levels)")]
112 InvalidLevel { level: usize, max_levels: usize },
113
114 #[error("Tile coordinates out of bounds: ({x}, {y}) at level {level} (max: {max_x}, {max_y})")]
116 TileOutOfBounds {
117 level: usize,
118 x: u32,
119 y: u32,
120 max_x: u32,
121 max_y: u32,
122 },
123
124 #[error("Slide not found: {slide_id}")]
126 SlideNotFound { slide_id: String },
127
128 #[error("Invalid quality: {quality} (must be 1-100)")]
130 InvalidQuality { quality: u8 },
131}