1use crate::packed_rtree::Error as PackedRtreeError;
2use cjseq::CjseqError;
3use flatbuffers::InvalidFlatbuffer;
4use serde_json;
5use thiserror::Error;
6
7#[derive(Debug, Error)]
10pub enum Error {
11 #[error("Missing magic bytes in FCB file header")]
13 MissingMagicBytes,
14
15 #[error("Required index is missing")]
16 NoIndex,
17
18 #[error("Attribute index not found")]
19 AttributeIndexNotFound,
20
21 #[error("Attribute index size overflow")]
22 AttributeIndexSizeOverflow,
23
24 #[error("No columns found in header")]
25 NoColumnsInHeader,
26
27 #[error("Missing required field of CityJSON: {0}")]
28 MissingRequiredField(String),
29
30 #[error("Invalid header size {0}, expected size between 8 and 1MB")]
31 IllegalHeaderSize(usize),
32
33 #[error("Invalid FlatBuffer format: {0}")]
34 InvalidFlatbuffer(#[from] InvalidFlatbuffer),
35
36 #[error("IO error: {0}")]
38 IoError(#[from] std::io::Error),
39
40 #[error("JSON error: {0}")]
41 JsonError(#[from] serde_json::Error),
42
43 #[error("R-tree error: {0}")]
44 RtreeError(#[from] PackedRtreeError),
45
46 #[error("Unsupported column type: {0}")]
48 UnsupportedColumnType(String),
49
50 #[error("Invalid attribute value: {msg}")]
51 InvalidAttributeValue { msg: String },
52
53 #[error("Unknown FlatCityBuf `{0}` tag {1}")]
59 UnknownEnumTag(&'static str, String),
60
61 #[error("Failed to create index: {0}")]
63 IndexCreationError(String),
64
65 #[error("Failed to execute query: {0}")]
66 QueryExecutionError(String),
67
68 #[cfg(feature = "http")]
70 #[error("HTTP client error: {0}")]
71 HttpClient(#[from] http_range_client::HttpError),
72
73 #[error("CityJSON error: {source}")]
75 CityJson {
76 #[from]
77 source: crate::cjerror::CjError,
78 },
79
80 #[error("Cjseq error: {source}")]
81 CjseqError {
82 #[from]
83 source: CjseqError,
84 },
85
86 #[error("StaticBTree error: {source}")]
87 StaticBTree {
88 #[from]
89 source: crate::static_btree::Error,
90 },
91}
92
93impl Error {
94 pub fn is_io_error(&self) -> bool {
96 matches!(self, Error::IoError(_))
97 }
98
99 pub fn is_format_error(&self) -> bool {
101 matches!(
102 self,
103 Error::MissingMagicBytes | Error::InvalidFlatbuffer(_) | Error::IllegalHeaderSize(_)
104 )
105 }
106
107 pub fn is_validation_error(&self) -> bool {
109 matches!(
110 self,
111 Error::UnsupportedColumnType(_) | Error::InvalidAttributeValue { .. }
112 )
113 }
114
115 pub fn is_index_error(&self) -> bool {
117 matches!(
118 self,
119 Error::IndexCreationError(_) | Error::QueryExecutionError(_)
120 )
121 }
122}
123
124pub type Result<T> = std::result::Result<T, Error>;