1use errno::Errno;
9use num_derive::FromPrimitive;
10use thiserror::Error;
11
12#[derive(Error, Debug)]
14pub enum CodesError {
15 #[error("ecCodes function returned a non-zero code {0}")]
18 Internal(#[from] CodesInternal),
19
20 #[error("libc function returned an error with code {0} and errno {1}")]
25 LibcNonZero(i32, Errno),
26
27 #[error("Error occured while opening the file: {0}")]
30 FileHandlingInterrupted(#[from] std::io::Error),
31
32 #[error("Cannot parse string as UTF8: {0}")]
34 CstrUTF8(#[from] std::str::Utf8Error),
35
36 #[error("String returned by ecCodes is not nul terminated: {0}")]
39 NulChar(#[from] std::ffi::FromBytesWithNulError),
40
41 #[error("The key is missing in present message")]
44 MissingKey,
45
46 #[error("Incorrect key size")]
49 IncorrectKeySize,
50
51 #[error("Requested key size is incorrect")]
53 WrongRequestedKeySize,
54
55 #[error("Requested key type is incorrect")]
57 WrongRequestedKeyType,
58
59 #[error("Cannot clone the message")]
62 CloneFailed,
63
64 #[error("Cannot create or manipulate keys iterator")]
66 KeysIteratorFailed,
67
68 #[error("Null pointer encountered where it should not be")]
73 NullPtr,
74
75 #[cfg(feature = "ndarray")]
78 #[error("error occured while converting CodesMessage to ndarray {0}")]
79 NdarrayConvert(#[from] MessageNdarrayError),
80
81 #[error("eccodes returned unrecognized error code: {0}")]
84 UnrecognizedErrorCode(i32),
85
86 #[error("Unrecognized native key type code: {0}")]
89 UnrecognizedKeyTypeCode(i32),
90}
91
92#[cfg(feature = "ndarray")]
94#[cfg_attr(docsrs, doc(cfg(feature = "ndarray")))]
95#[derive(PartialEq, Clone, Error, Debug)]
96pub enum MessageNdarrayError {
97 #[error("Requested key {0} has a different type than expected")]
100 UnexpectedKeyType(String),
101
102 #[error("The length of the values array ({0}) is different than expected ({1})")]
105 UnexpectedValuesLength(usize, usize),
106
107 #[error("Requested key {0} has a value out of expected range")]
110 UnexpectedKeyValue(String),
111
112 #[error("Error occured while converting to ndarray: {0}")]
115 InvalidShape(#[from] ndarray::ShapeError),
116
117 #[error(transparent)]
120 IntCasting(#[from] std::num::TryFromIntError),
121}
122
123#[derive(Copy, Eq, PartialEq, Clone, Ord, PartialOrd, Hash, Error, Debug, FromPrimitive)]
126pub enum CodesInternal {
127 #[error("No error")]
129 CodesSuccess = 0,
130
131 #[error("End of resource reached")]
133 CodesEndOfFile = -1,
134
135 #[error("Internal error")]
137 CodesInternalError = -2,
138
139 #[error("Passed buffer is too small")]
141 CodesBufferTooSmall = -3,
142
143 #[error("Function not yet implemented")]
145 CodesNotImplemented = -4,
146
147 #[error("Missing 7777 at end of message")]
149 Codes7777NotFound = -5,
150
151 #[error("Passed array is too small")]
153 CodesArrayTooSmall = -6,
154
155 #[error("File not found")]
157 CodesFileNotFound = -7,
158
159 #[error("Code not found in code table")]
161 CodesCodeNotFoundInTable = -8,
162
163 #[error("Array size mismatch")]
165 CodesWrongArraySize = -9,
166
167 #[error("Key/value not found")]
169 CodesNotFound = -10,
170
171 #[error("Input output problem")]
173 CodesIoProblem = -11,
174
175 #[error("Message invalid")]
177 CodesInvalidMessage = -12,
178
179 #[error("Decoding invalid")]
181 CodesDecodingError = -13,
182
183 #[error("Encoding invalid")]
185 CodesEncodingError = -14,
186
187 #[error("Code cannot unpack because of string too small")]
189 CodesNoMoreInSet = -15,
190
191 #[error("Problem with calculation of geographic attributes")]
193 CodesGeocalculusProblem = -16,
194
195 #[error("Memory allocation error")]
197 CodesOutOfMemory = -17,
198
199 #[error("Value is read only")]
201 CodesReadOnly = -18,
202
203 #[error("Invalid argument")]
205 CodesInvalidArgument = -19,
206
207 #[error("Null handle")]
209 CodesNullHandle = -20,
210
211 #[error("Invalid section number")]
213 CodesInvalidSectionNumber = -21,
214
215 #[error("Value cannot be missing")]
217 CodesValueCannotBeMissing = -22,
218
219 #[error("Wrong message length")]
221 CodesWrongLength = -23,
222
223 #[error("Invalid key type")]
225 CodesInvalidType = -24,
226
227 #[error("Unable to set step")]
229 CodesWrongStep = -25,
230
231 #[error("Wrong units for step (step must be integer)")]
233 CodesWrongStepUnit = -26,
234
235 #[error("Invalid file id")]
237 CodesInvalidFile = -27,
238
239 #[error("Invalid grib id")]
241 CodesInvalidGrib = -28,
242
243 #[error("Invalid index id")]
245 CodesInvalidIndex = -29,
246
247 #[error("Invalid iterator id")]
249 CodesInvalidIterator = -30,
250
251 #[error("Invalid keys iterator id")]
253 CodesInvalidKeysIterator = -31,
254
255 #[error("Invalid nearest id")]
257 CodesInvalidNearest = -32,
258
259 #[error("Invalid order by")]
261 CodesInvalidOrderby = -33,
262
263 #[error("Missing a key from the fieldset")]
265 CodesMissingKey = -34,
266
267 #[error("The point is out of the grid area")]
269 CodesOutOfArea = -35,
270
271 #[error("Concept no match")]
273 CodesConceptNoMatch = -36,
274
275 #[error("Hash array no match")]
277 CodesHashArrayNoMatch = -37,
278
279 #[error("Definitions files not found")]
281 CodesNoDefinitions = -38,
282
283 #[error("Wrong type while packing")]
285 CodesWrongType = -39,
286
287 #[error("End of resource")]
289 CodesEnd = -40,
290
291 #[error("Unable to code a field without values")]
293 CodesNoValues = -41,
294
295 #[error("Grid description is wrong or inconsistent")]
297 CodesWrongGrid = -42,
298
299 #[error("End of index reached")]
301 CodesEndOfIndex = -43,
302
303 #[error("Null index")]
305 CodesNullIndex = -44,
306
307 #[error("End of resource reached when reading message")]
309 CodesPrematureEndOfFile = -45,
310
311 #[error("An internal array is too small")]
313 CodesInternalArrayTooSmall = -46,
314
315 #[error("Message is too large for the current architecture")]
317 CodesMessageTooLarge = -47,
318
319 #[error("Constant field")]
321 CodesConstantField = -48,
322
323 #[error("Switch unable to find a matching case")]
325 CodesSwitchNoMatch = -49,
326
327 #[error("Underflow")]
329 CodesUnderflow = -50,
330
331 #[error("Message malformed")]
333 CodesMessageMalformed = -51,
334
335 #[error("Index is corrupted")]
337 CodesCorruptedIndex = -52,
338
339 #[error("Invalid number of bits per value")]
341 CodesInvalidBpv = -53,
342
343 #[error("Edition of two messages is different")]
345 CodesDifferentEdition = -54,
346
347 #[error("Value is different")]
349 CodesValueDifferent = -55,
350
351 #[error("Invalid key value")]
353 CodesInvalidKeyValue = -56,
354
355 #[error("String is smaller than requested")]
357 CodesStringTooSmall = -57,
358
359 #[error("Wrong type conversion")]
361 CodesWrongConversion = -58,
362
363 #[error("Missing BUFR table entry for descriptor")]
365 CodesMissingBufrEntry = -59,
366
367 #[error("Null pointer")]
369 CodesNullPointer = -60,
370
371 #[error("Attribute is already present = cannot add")]
373 CodesAttributeClash = -61,
374
375 #[error("Too many attributes. Increase MAX_ACCESSOR_ATTRIBUTES")]
377 CodesTooManyAttributes = -62,
378
379 #[error("Attribute not found")]
381 CodesAttributeNotFound = -63,
382
383 #[error("Edition not supported")]
385 CodesUnsupportedEdition = -64,
386
387 #[error("Value out of coding range")]
389 CodesOutOfRange = -65,
390
391 #[error("Size of bitmap is incorrect")]
393 CodesWrongBitmapSize = -66,
394
395 #[error("Functionality not enabled")]
397 CodesFunctionalityNotEnabled = -67,
398}