1pub type Result<T> = core::result::Result<T, StacError>;
5
6#[derive(Debug, thiserror::Error)]
8pub enum StacError {
9 #[error("Invalid STAC type: expected {expected}, found {found}")]
11 InvalidType {
12 expected: String,
14 found: String,
16 },
17
18 #[error("Invalid STAC version: {0}")]
20 InvalidVersion(String),
21
22 #[error("Missing required field: {0}")]
24 MissingField(String),
25
26 #[error("Invalid field value for {field}: {reason}")]
28 InvalidFieldValue {
29 field: String,
31 reason: String,
33 },
34
35 #[error("Invalid URL: {0}")]
37 InvalidUrl(String),
38
39 #[error("Invalid geometry: {0}")]
41 InvalidGeometry(String),
42
43 #[error("Invalid datetime: {0}")]
45 InvalidDatetime(String),
46
47 #[error("Invalid bbox: {0}")]
49 InvalidBbox(String),
50
51 #[error("Serialization error: {0}")]
53 Serialization(String),
54
55 #[error("Deserialization error: {0}")]
57 Deserialization(String),
58
59 #[cfg(feature = "reqwest")]
61 #[error("HTTP request error: {0}")]
62 Http(String),
63
64 #[error("Asset not found: {0}")]
66 AssetNotFound(String),
67
68 #[error("Link not found: {0}")]
70 LinkNotFound(String),
71
72 #[error("Extension not found: {0}")]
74 ExtensionNotFound(String),
75
76 #[error("Invalid extension data for {extension}: {reason}")]
78 InvalidExtension {
79 extension: String,
81 reason: String,
83 },
84
85 #[error("IO error: {0}")]
87 Io(String),
88
89 #[error("Invalid search parameters: {0}")]
91 InvalidSearchParams(String),
92
93 #[error("API response error: {0}")]
95 ApiResponse(String),
96
97 #[error("Builder error: {0}")]
99 Builder(String),
100
101 #[error("Item already exists: {0}")]
103 AlreadyExists(String),
104
105 #[error("Not found: {0}")]
107 NotFound(String),
108
109 #[error("Invalid item: {0}")]
111 InvalidItem(String),
112
113 #[error("{0}")]
115 Other(String),
116}
117
118impl From<serde_json::Error> for StacError {
119 fn from(err: serde_json::Error) -> Self {
120 if err.is_data() {
121 StacError::Deserialization(err.to_string())
122 } else {
123 StacError::Serialization(err.to_string())
124 }
125 }
126}
127
128impl From<url::ParseError> for StacError {
129 fn from(err: url::ParseError) -> Self {
130 StacError::InvalidUrl(err.to_string())
131 }
132}
133
134impl From<chrono::ParseError> for StacError {
135 fn from(err: chrono::ParseError) -> Self {
136 StacError::InvalidDatetime(err.to_string())
137 }
138}
139
140#[cfg(feature = "reqwest")]
141impl From<reqwest::Error> for StacError {
142 fn from(err: reqwest::Error) -> Self {
143 StacError::Http(err.to_string())
144 }
145}
146
147impl From<geojson::Error> for StacError {
148 fn from(err: geojson::Error) -> Self {
149 StacError::InvalidGeometry(err.to_string())
150 }
151}
152
153#[cfg(feature = "std")]
154impl From<std::io::Error> for StacError {
155 fn from(err: std::io::Error) -> Self {
156 StacError::Io(err.to_string())
157 }
158}