async_geotiff/error.rs
1use thiserror::Error;
2
3/// Result type returned by the crate's fallible operations.
4pub type AgResult<T> = Result<T, AgError>;
5
6/// Reader, rendering and request-control failures.
7///
8/// Request admission failures are returned without waiting for capacity.
9/// Cancellation and deadlines stop cooperative work; they do not forcibly stop
10/// CPU closures that are already running.
11#[derive(Debug, Error)]
12pub enum AgError {
13 /// An allocation, source shape or work request exceeds a configured limit.
14 #[error("work resource limit: {0}")]
15 ResourceLimit(String),
16
17 /// The request limiter has no free admission slot.
18 #[error("request admission limit reached")]
19 Overloaded,
20
21 /// The request's configured or per-call deadline expired.
22 #[error("request deadline exceeded")]
23 DeadlineExceeded,
24
25 /// The caller explicitly cancelled the request.
26 #[error("request cancelled")]
27 Cancelled,
28
29 /// A query, style document or band selection is invalid.
30 #[error("invalid query parameter `{name}`: {msg}")]
31 Query {
32 /// Parameter name or document path identifying the invalid input.
33 name: String,
34 /// Explanation of the validation failure.
35 msg: String,
36 },
37
38 /// The requested tile matrix set name is not supported.
39 #[error("unknown TMS: {0}")]
40 UnknownTms(String),
41
42 /// The requested built-in color map name is not supported.
43 #[error("unknown colormap: {0}")]
44 UnknownColormap(String),
45
46 /// A tile coordinate is outside its matrix or supported zoom range.
47 #[error("out-of-bounds tile: z={z} x={x} y={y}")]
48 TileOutOfBounds {
49 /// Requested zoom level.
50 z: u8,
51 /// Requested tile column.
52 x: u32,
53 /// Requested tile row.
54 y: u32,
55 },
56
57 /// Unsupported pixel data, channel layout or unavailable output format.
58 #[error("unsupported pixel format: {0}")]
59 UnsupportedPixel(String),
60
61 /// Required georeferencing metadata is absent.
62 #[error("missing geo metadata: {0}")]
63 MissingGeo(&'static str),
64
65 /// A color formula could not be parsed or applied.
66 #[error("color formula: {0}")]
67 ColorFormula(String),
68
69 /// Reprojection setup or raster warping failed.
70 #[error("warp: {0}")]
71 Warp(String),
72
73 /// A coordinate fell outside the source/target projection's valid
74 /// domain. Not a failure: the tiler treats this as "nothing here"
75 /// and returns a transparent tile (mirrors rio-tiler/titiler).
76 #[error("projection domain: {0}")]
77 ProjectionDomain(String),
78
79 /// An underlying I/O operation failed.
80 #[error("io: {0}")]
81 Io(#[from] std::io::Error),
82
83 /// TIFF metadata, pixel decoding, image encoding or a source operation failed.
84 #[error("async-tiff: {0}")]
85 Tiff(String),
86
87 /// Mosaic discovery, asset access or composition failed.
88 #[error("mosaic: {0}")]
89 Mosaic(String),
90
91 /// An image encoder failed.
92 #[error("encode: {0}")]
93 Encode(#[from] image::ImageError),
94}
95
96impl AgError {
97 /// Construct a validation error for a parameter name or document path.
98 pub fn query(name: impl Into<String>, msg: impl Into<String>) -> Self {
99 Self::Query {
100 name: name.into(),
101 msg: msg.into(),
102 }
103 }
104}
105
106#[cfg(test)]
107mod tests {
108 use super::*;
109
110 #[test]
111 fn query_helper_builds_message() {
112 let e = AgError::query("bidx", "not an integer");
113 assert_eq!(
114 format!("{}", e),
115 "invalid query parameter `bidx`: not an integer"
116 );
117 }
118
119 #[test]
120 fn unknown_tms_displays() {
121 let e = AgError::UnknownTms("LolMercator".into());
122 assert_eq!(format!("{}", e), "unknown TMS: LolMercator");
123 }
124}