Skip to main content

geonative_image/
error.rs

1//! Per-crate error type. Wraps the underlying decoder errors plus the
2//! sidecar / format failure modes.
3
4use thiserror::Error;
5
6pub type Result<T> = std::result::Result<T, ImageError>;
7
8#[derive(Debug, Error)]
9pub enum ImageError {
10    #[error("I/O error: {0}")]
11    Io(#[from] std::io::Error),
12
13    #[error("JPEG decode: {0}")]
14    Jpeg(String),
15
16    #[error("PNG decode: {0}")]
17    Png(String),
18
19    #[error("missing world file: expected {expected} next to image {image}")]
20    MissingWorldFile { image: String, expected: String },
21
22    #[error("world file parse: {0}")]
23    WorldFile(String),
24
25    #[error("unsupported image feature: {0}")]
26    Unsupported(String),
27
28    #[error("malformed input: {0}")]
29    Malformed(String),
30}
31
32impl ImageError {
33    pub fn malformed(msg: impl Into<String>) -> Self {
34        Self::Malformed(msg.into())
35    }
36
37    pub fn unsupported(msg: impl Into<String>) -> Self {
38        Self::Unsupported(msg.into())
39    }
40
41    pub fn world_file(msg: impl Into<String>) -> Self {
42        Self::WorldFile(msg.into())
43    }
44}
45
46impl From<ImageError> for geonative_core::Error {
47    fn from(e: ImageError) -> Self {
48        match e {
49            ImageError::Io(io) => geonative_core::Error::Io(io),
50            ImageError::Unsupported(s) => geonative_core::Error::unsupported(s),
51            other => geonative_core::Error::malformed(other.to_string()),
52        }
53    }
54}