-
Notifications
You must be signed in to change notification settings - Fork 91
/
errors.rs
94 lines (88 loc) · 2.82 KB
/
errors.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use libc::c_int;
use thiserror::Error;
use gdal_sys::{CPLErr, OGRErr, OGRFieldType, OGRwkbGeometryType};
pub type Result<T> = std::result::Result<T, GdalError>;
#[derive(Clone, Debug, Error)]
pub enum GdalError {
#[error("FfiNulError")]
FfiNulError(#[from] std::ffi::NulError),
#[error("FfiIntoStringError")]
FfiIntoStringError(#[from] std::ffi::IntoStringError),
#[error("StrUtf8Error")]
StrUtf8Error(#[from] std::str::Utf8Error),
#[cfg(feature = "ndarray")]
#[error("NdarrayShapeError")]
NdarrayShapeError(#[from] ndarray::ShapeError),
#[error("CPL error class: '{class:?}', error number: '{number}', error msg: '{msg}'")]
CplError {
class: CPLErr::Type,
number: c_int,
msg: String,
},
#[error("GDAL method '{method_name}' returned a NULL pointer. Error msg: '{msg}'")]
NullPointer {
method_name: &'static str,
msg: String,
},
#[error("Can't cast to f64")]
CastToF64Error,
#[error("OGR method '{method_name}' returned error: '{err:?}'")]
OgrError {
err: OGRErr::Type,
method_name: &'static str,
},
#[error("Unhandled type '{field_type:?}' on OGR method {method_name}")]
UnhandledFieldType {
field_type: OGRFieldType::Type,
method_name: &'static str,
},
#[error("Invalid field name '{field_name}' used on method {method_name}")]
InvalidFieldName {
field_name: String,
method_name: &'static str,
},
#[error("Invalid field index '{index}' used on method '{method_name}'")]
InvalidFieldIndex {
index: usize,
method_name: &'static str,
},
#[error("Unlinked Geometry on method '{method_name}'")]
UnlinkedGeometry { method_name: &'static str },
#[error(
"Invalid coordinate range while transforming points from '{from}' to '{to}': '{msg:?}'"
)]
InvalidCoordinateRange {
from: String,
to: String,
msg: Option<String>,
},
#[error("Axis not found for key '{key}' in method '{method_name}'")]
AxisNotFoundError {
key: String,
method_name: &'static str,
},
#[error("Unsupported GDAL geometry type")]
UnsupportedGdalGeometryType(OGRwkbGeometryType::Type),
#[error("Unable to unlink mem file: {file_name}")]
UnlinkMemFile { file_name: String },
#[error("BadArgument")]
BadArgument(String),
}
/// A wrapper for [`CPLErr::Type`] that reflects it as an enum
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
#[repr(C)]
pub enum CplErrType {
None = 0,
Debug = 1,
Warning = 2,
Failure = 3,
Fatal = 4,
}
impl From<CPLErr::Type> for CplErrType {
fn from(error_type: CPLErr::Type) -> Self {
if error_type > 4 {
return Self::None; // fallback type, should not happen
}
unsafe { std::mem::transmute(error_type) }
}
}