Skip to main content

tiff_reader/
error.rs

1use thiserror::Error;
2
3pub type Result<T> = std::result::Result<T, Error>;
4
5#[derive(Debug, Error)]
6pub enum Error {
7    #[error("I/O error reading {1}: {0}")]
8    Io(#[source] std::io::Error, String),
9
10    #[error("not a TIFF file: invalid magic bytes")]
11    InvalidMagic,
12
13    #[error("unsupported TIFF version: {0}")]
14    UnsupportedVersion(u16),
15
16    #[error("IFD index {0} not found")]
17    IfdNotFound(usize),
18
19    #[error("tag {0} not found in IFD")]
20    TagNotFound(u16),
21
22    #[error("unexpected tag type {actual} for tag {tag}, expected {expected}")]
23    UnexpectedTagType {
24        tag: u16,
25        expected: &'static str,
26        actual: u16,
27    },
28
29    #[error("unsupported compression: {0}")]
30    UnsupportedCompression(u16),
31
32    #[error("unsupported predictor: {0}")]
33    UnsupportedPredictor(u16),
34
35    #[error("unsupported planar configuration: {0}")]
36    UnsupportedPlanarConfiguration(u16),
37
38    #[error("unsupported bits per sample: {0}")]
39    UnsupportedBitsPerSample(u16),
40
41    #[error("unsupported sample format: {0}")]
42    UnsupportedSampleFormat(u16),
43
44    #[error("decompression failed for strip/tile {index}: {reason}")]
45    DecompressionFailed { index: usize, reason: String },
46
47    #[error("data truncated at offset {offset}: need {needed} bytes, have {available}")]
48    Truncated {
49        offset: u64,
50        needed: u64,
51        available: u64,
52    },
53
54    #[error("offset {offset} with length {length} is out of bounds for a {data_len}-byte file")]
55    OffsetOutOfBounds {
56        offset: u64,
57        length: u64,
58        data_len: u64,
59    },
60
61    #[error("invalid TIFF tag {tag}: {reason}")]
62    InvalidTagValue { tag: u16, reason: String },
63
64    #[error("invalid image layout: {0}")]
65    InvalidImageLayout(String),
66
67    #[error("type mismatch: expected {expected}, found {actual}")]
68    TypeMismatch {
69        expected: &'static str,
70        actual: String,
71    },
72
73    #[error("{0}")]
74    Other(String),
75}