geonative_core/error.rs
1//! The crate-wide error type plus its `Result` alias.
2//!
3//! ## Design
4//!
5//! `geonative-core` defines one neutral error enum that every downstream
6//! crate (`filegdb`, `geoparquet`, `shapefile`, `mvt`, …) can map into via
7//! `From`. Drivers keep their own dialect-specific error types (`GdbError`,
8//! `ShpError`, `MvtError`, …) for in-crate use; conversion to this
9//! `Error` happens at the public-API boundary.
10//!
11//! ## Variants and when to use them
12//!
13//! - **`Io`** — wraps any `std::io::Error` unchanged (auto via `From`).
14//! - **`Malformed`** — bytes parsed but didn't match the expected format
15//! (truncated header, bad magic, varint overflow, etc.).
16//! - **`Unsupported`** — input is valid but uses a feature we deliberately
17//! don't handle (Z/M variants in v0.1, compressed FileGDB tables, etc.).
18//! Distinguishes "the file is broken" from "we haven't built this yet".
19//! - **`Schema`** — runtime schema mismatch (wrong attribute arity, type
20//! mismatch on a non-null field, etc.).
21//! - **`LayerNotFound`** — caller asked for a layer name that doesn't exist
22//! in this dataset.
23//! - **`Other`** — escape hatch for caller-supplied messages. Try not to
24//! reach for this in new code.
25
26use thiserror::Error;
27
28pub type Result<T> = std::result::Result<T, Error>;
29
30#[derive(Debug, Error)]
31pub enum Error {
32 #[error("I/O error: {0}")]
33 Io(#[from] std::io::Error),
34
35 #[error("malformed input: {0}")]
36 Malformed(String),
37
38 #[error("unsupported feature: {0}")]
39 Unsupported(String),
40
41 #[error("schema mismatch: {0}")]
42 Schema(String),
43
44 #[error("layer not found: {0}")]
45 LayerNotFound(String),
46
47 #[error("{0}")]
48 Other(String),
49}
50
51impl Error {
52 pub fn malformed(msg: impl Into<String>) -> Self {
53 Self::Malformed(msg.into())
54 }
55
56 pub fn unsupported(msg: impl Into<String>) -> Self {
57 Self::Unsupported(msg.into())
58 }
59
60 pub fn schema(msg: impl Into<String>) -> Self {
61 Self::Schema(msg.into())
62 }
63}