• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

geo-engine / geoengine / 3676601107

pending completion
3676601107

push

github

GitHub
Merge #695

42001 of 50014 relevant lines covered (83.98%)

2.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

53.85
/datatypes/src/error.rs
1
use crate::{
2
    collections::FeatureCollectionError,
3
    primitives::{BoundingBox2D, Coordinate2D, PrimitivesError, TimeInstance, TimeInterval},
4
    raster::RasterDataType,
5
    spatial_reference::SpatialReference,
6
};
7
use snafu::{prelude::*, AsErrorSource, ErrorCompat, IntoError};
8
use std::{any::Any, convert::Infallible, path::PathBuf, sync::Arc};
9

10
use crate::util::Result;
11

12
pub trait ErrorSource: std::error::Error + Send + Sync + Any + 'static + AsErrorSource {
13
    fn boxed(self) -> Box<dyn ErrorSource>
2✔
14
    where
15
        Self: Sized + 'static,
16
    {
17
        Box::new(self)
2✔
18
    }
19

20
    fn into_any_arc(self: Arc<Self>) -> Arc<(dyn Any + Send + Sync)>;
21
}
22

23
impl ErrorSource for dyn std::error::Error + Send + Sync + 'static {
24
    fn into_any_arc(self: Arc<Self>) -> Arc<(dyn Any + Send + Sync)> {
×
25
        Arc::new(self)
×
26
    }
27
}
28

29
impl<T> ErrorSource for T
30
where
31
    T: std::error::Error + Send + Sync + 'static,
32
{
33
    fn into_any_arc(self: Arc<Self>) -> Arc<(dyn Any + Send + Sync)> {
1✔
34
        self
×
35
    }
36
}
37

38
pub trait BoxedResultExt<T, E>: Sized {
39
    fn boxed_context<C, E2>(self, context: C) -> Result<T, E2>
40
    where
41
        C: IntoError<E2, Source = Box<dyn ErrorSource>>,
42
        E2: std::error::Error + ErrorCompat;
43
}
44

45
impl<T, E> BoxedResultExt<T, E> for Result<T, E>
46
where
47
    E: ErrorSource,
48
{
49
    fn boxed_context<C, E2>(self, context: C) -> Result<T, E2>
25✔
50
    where
51
        C: IntoError<E2, Source = Box<dyn ErrorSource>>,
52
        E2: std::error::Error + ErrorCompat,
53
    {
54
        self.map_err(|e| Box::new(e) as Box<dyn ErrorSource>)
53✔
55
            .context(context)
25✔
56
    }
57
}
58

59
#[derive(Debug, Snafu)]
60
#[snafu(visibility(pub(crate)))]
61
#[snafu(context(suffix(false)))] // disables default `Snafu` suffix
62
pub enum Error {
63
    #[snafu(display("Arrow internal error: {:?}", source))]
64
    ArrowInternal {
65
        source: arrow::error::ArrowError,
66
    },
67

68
    #[snafu(display("ProjInternal error: {:?}", source))]
69
    ProjInternal {
70
        source: proj::ProjError,
71
    },
72
    #[snafu(display("No CoordinateProjector available for: {:?} --> {:?}", from, to))]
73
    NoCoordinateProjector {
74
        from: SpatialReference,
75
        to: SpatialReference,
76
    },
77
    #[snafu(display(
78
        "Could not resolve a Proj string for this SpatialReference: {}",
79
        spatial_ref
80
    ))]
81
    ProjStringUnresolvable {
82
        spatial_ref: SpatialReference,
83
    },
84

85
    #[snafu(display("Field is reserved or already in use: {}", name))]
86
    ColumnNameConflict {
87
        name: String,
88
    },
89

90
    #[snafu(display("Start `{}` must be before end `{}`", start, end))]
91
    TimeIntervalEndBeforeStart {
92
        start: i64,
93
        end: i64,
94
    },
95

96
    #[snafu(display(
97
        "{} cannot be unioned with {} since the intervals are neither intersecting nor contiguous",
98
        i1,
99
        i2
100
    ))]
101
    TimeIntervalUnmatchedIntervals {
102
        i1: TimeInterval,
103
        i2: TimeInterval,
104
    },
105

106
    #[snafu(display(
107
        "{} must be larger than {} and {} must be smaller than {}",
108
        start.inner(),
109
        min.inner(),
110
        end.inner(),
111
        max.inner()
112
    ))]
113
    TimeIntervalOutOfBounds {
114
        start: TimeInstance,
115
        end: TimeInstance,
116
        min: TimeInstance,
117
        max: TimeInstance,
118
    },
119

120
    #[snafu(display(
121
        "{:?} is not a valid index in the bounds {:?}, {:?} ",
122
        index,
123
        min_index,
124
        max_index,
125
    ))]
126
    GridIndexOutOfBounds {
127
        index: Vec<isize>,
128
        min_index: Vec<isize>,
129
        max_index: Vec<isize>,
130
    },
131

132
    #[snafu(display("{:?} is not a valid index in the bounds 0, {:?} ", index, max_index,))]
133
    LinearIndexOutOfBounds {
134
        index: usize,
135
        max_index: usize,
136
    },
137

138
    #[snafu(display("Invalid GridIndex ({:?}), reason: \"{}\".", grid_index, description))]
139
    InvalidGridIndex {
140
        grid_index: Vec<usize>,
141
        description: &'static str,
142
    },
143

144
    #[snafu(display("Invalid raster operation. Reason: \"{}\".", description))]
145
    InvalidRasterOperation {
146
        description: &'static str,
147
    },
148

149
    #[snafu(display(
150
        "Dimension capacity  ≠ data capacity ({} ≠ {})",
151
        dimension_cap,
152
        data_cap
153
    ))]
154
    DimensionCapacityDoesNotMatchDataCapacity {
155
        dimension_cap: usize,
156
        data_cap: usize,
157
    },
158

159
    #[snafu(display(
160
        "The conditions ll.x <= ur.x && ll.y <= ur.y are not met by ll:{} ur:{}",
161
        lower_left_coordinate,
162
        upper_right_coordinate
163
    ))]
164
    InvalidBoundingBox {
165
        lower_left_coordinate: Coordinate2D,
166
        upper_right_coordinate: Coordinate2D,
167
    },
168

169
    #[snafu(display(
170
        "Mask length ≠ collection length ({} ≠ {})",
171
        mask_length,
172
        collection_length
173
    ))]
174
    MaskLengthDoesNotMatchCollectionLength {
175
        mask_length: usize,
176
        collection_length: usize,
177
    },
178

179
    FeatureCollection {
180
        source: FeatureCollectionError,
181
    },
182

183
    #[snafu(display("FeatureData exception: {}", details))]
184
    FeatureData {
185
        details: String,
186
    },
187

188
    #[snafu(display("FeatureCollectionBuilder exception: {}", details))]
189
    FeatureCollectionBuilder {
190
        details: String,
191
    },
192

193
    #[snafu(display("Plot exception: {}", details))]
194
    Plot {
195
        details: String,
196
    },
197

198
    #[snafu(display("Colorizer exception: {}", details))]
199
    Colorizer {
200
        details: String,
201
    },
202

203
    Primitives {
204
        source: PrimitivesError,
205
    },
206

207
    #[snafu(display("Blit exception: {}", details))]
208
    Blit {
209
        details: String,
210
    },
211
    #[snafu(display("NonMatchingRasterTypes: a=\"{:?}\", b=\"{:?}\"", a, b))]
212
    NonMatchingRasterTypes {
213
        a: RasterDataType,
214
        b: RasterDataType,
215
    },
216
    #[snafu(display(
217
        "Invalid Grid bounds: Each eleemnt in {:?} must be <= the corresponding element in {:?}.",
218
        min,
219
        max
220
    ))]
221
    InvalidGridBounds {
222
        min: Vec<isize>,
223
        max: Vec<isize>,
224
    },
225
    #[snafu(display("InvalidSpatialReferenceString: {}", spatial_reference_string))]
226
    InvalidSpatialReferenceString {
227
        spatial_reference_string: String,
228
    },
229

230
    #[snafu(display("ParseU32: {}", source))]
231
    ParseU32 {
232
        source: <u32 as std::str::FromStr>::Err,
233
    },
234
    InvalidTypedGridConversion,
235
    InvalidTypedValueConversion,
236

237
    InvalidUuid,
238

239
    #[snafu(display("NoDateTimeValid: {:?}", time_instance))]
240
    NoDateTimeValid {
241
        time_instance: TimeInstance,
242
    },
243

244
    DateTimeOutOfBounds {
245
        year: i32,
246
        month: u32,
247
        day: u32,
248
    },
249

250
    #[snafu(display(
251
        "The supplied spatial bounds are empty: {} {}",
252
        lower_left_coordinate,
253
        upper_right_coordinate
254
    ))]
255
    EmptySpatialBounds {
256
        lower_left_coordinate: Coordinate2D,
257
        upper_right_coordinate: Coordinate2D,
258
    },
259

260
    #[snafu(display("GdalError: {}", source))]
261
    Gdal {
262
        source: gdal::errors::GdalError,
263
    },
264

265
    GdalRasterDataTypeNotSupported,
266

267
    NoMatchingVectorDataTypeForOgrGeometryType,
268

269
    NoMatchingFeatureDataTypeForOgrFieldType,
270

271
    InvalidProjDefinition {
272
        proj_definition: String,
273
    },
274
    NoAreaOfUseDefined {
275
        proj_string: String,
276
    },
277
    SpatialBoundsDoNotIntersect {
278
        bounds_a: BoundingBox2D,
279
        bounds_b: BoundingBox2D,
280
    },
281

282
    OutputBboxEmpty {
283
        bbox: BoundingBox2D,
284
    },
285

286
    WrongMetadataType,
287

288
    #[snafu(display(
289
        "The conditions ul.x < lr.x && ul.y < lr.y are not met by ul:{} lr:{}",
290
        upper_left_coordinate,
291
        lower_right_coordinate
292
    ))]
293
    InvalidSpatialPartition {
294
        upper_left_coordinate: Coordinate2D,
295
        lower_right_coordinate: Coordinate2D,
296
    },
297

298
    #[snafu(display("MissingRasterProperty Error: {}", property))]
299
    MissingRasterProperty {
300
        property: String,
301
    },
302

303
    TimeStepIterStartMustNotBeBeginOfTime,
304

305
    MinMustBeSmallerThanMax {
306
        min: f64,
307
        max: f64,
308
    },
309

310
    ColorizerRescaleNotSupported {
311
        colorizer: String,
312
    },
313

314
    SpatialReferencesDoNotIntersect {
315
        a: SpatialReference,
316
        b: SpatialReference,
317
    },
318

319
    Io {
320
        source: std::io::Error,
321
    },
322

323
    SubPathMustNotEscapeBasePath {
324
        base: PathBuf,
325
        sub_path: PathBuf,
326
    },
327
}
328

329
impl From<arrow::error::ArrowError> for Error {
330
    fn from(source: arrow::error::ArrowError) -> Self {
×
331
        Error::ArrowInternal { source }
332
    }
333
}
334

335
impl From<proj::ProjError> for Error {
336
    fn from(source: proj::ProjError) -> Self {
×
337
        Error::ProjInternal { source }
338
    }
339
}
340

341
impl From<Infallible> for Error {
342
    fn from(_: Infallible) -> Self {
343
        unreachable!("This function cannot be called on a non-failing type")
344
    }
345
}
346

347
impl From<gdal::errors::GdalError> for Error {
348
    fn from(gdal_error: gdal::errors::GdalError) -> Self {
×
349
        Self::Gdal { source: gdal_error }
350
    }
351
}
352

353
impl From<std::io::Error> for Error {
354
    fn from(e: std::io::Error) -> Self {
1✔
355
        Self::Io { source: e }
356
    }
357
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc