-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy patherrors.py
381 lines (236 loc) · 8.49 KB
/
errors.py
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
#
# (C) Copyright 2017- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation nor
# does it submit to any jurisdiction.
#
"""
Exception class hierarchy
"""
from .bindings import ENC, ffi, lib
class GribInternalError(Exception):
"""
@brief Wrap errors coming from the C API in a Python exception object.
Base class for all exceptions
"""
def __init__(self, value):
# Call the base class constructor with the parameters it needs
Exception.__init__(self, value)
if type(value) is int:
self.msg = ffi.string(lib.grib_get_error_message(value)).decode(ENC)
else:
self.msg = value
def __str__(self):
return self.msg
class FunctionalityNotEnabledError(GribInternalError):
"""Functionality not enabled."""
class WrongBitmapSizeError(GribInternalError):
"""Size of bitmap is incorrect."""
class OutOfRangeError(GribInternalError):
"""Value out of coding range."""
class UnsupportedEditionError(GribInternalError):
"""Edition not supported.."""
class AttributeNotFoundError(GribInternalError):
"""Attribute not found.."""
class TooManyAttributesError(GribInternalError):
"""Too many attributes. Increase MAX_ACCESSOR_ATTRIBUTES."""
class AttributeClashError(GribInternalError):
"""Attribute is already present, cannot add."""
class NullPointerError(GribInternalError):
"""Null pointer."""
class MissingBufrEntryError(GribInternalError):
"""Missing BUFR table entry for descriptor."""
class WrongConversionError(GribInternalError):
"""Wrong type conversion."""
class StringTooSmallError(GribInternalError):
"""String is smaller than requested."""
class InvalidKeyValueError(GribInternalError):
"""Invalid key value."""
class ValueDifferentError(GribInternalError):
"""Value is different."""
class DifferentEditionError(GribInternalError):
"""Edition of two messages is different."""
class InvalidBitsPerValueError(GribInternalError):
"""Invalid number of bits per value."""
class CorruptedIndexError(GribInternalError):
"""Index is corrupted."""
class MessageMalformedError(GribInternalError):
"""Message malformed."""
class UnderflowError(GribInternalError):
"""Underflow."""
class SwitchNoMatchError(GribInternalError):
"""Switch unable to find a matching case."""
class ConstantFieldError(GribInternalError):
"""Constant field."""
class MessageTooLargeError(GribInternalError):
"""Message is too large for the current architecture."""
class InternalArrayTooSmallError(GribInternalError):
"""An internal array is too small."""
class PrematureEndOfFileError(GribInternalError):
"""End of resource reached when reading message."""
class NullIndexError(GribInternalError):
"""Null index."""
class EndOfIndexError(GribInternalError):
"""End of index reached."""
class WrongGridError(GribInternalError):
"""Grid description is wrong or inconsistent."""
class NoValuesError(GribInternalError):
"""Unable to code a field without values."""
class EndError(GribInternalError):
"""End of resource."""
class WrongTypeError(GribInternalError):
"""Wrong type while packing."""
class NoDefinitionsError(GribInternalError):
"""Definitions files not found."""
class HashArrayNoMatchError(GribInternalError):
"""Hash array no match."""
class ConceptNoMatchError(GribInternalError):
"""Concept no match."""
class OutOfAreaError(GribInternalError):
"""The point is out of the grid area."""
class MissingKeyError(GribInternalError):
"""Missing a key from the fieldset."""
class InvalidOrderByError(GribInternalError):
"""Invalid order by."""
class InvalidNearestError(GribInternalError):
"""Invalid nearest id."""
class InvalidKeysIteratorError(GribInternalError):
"""Invalid keys iterator id."""
class InvalidIteratorError(GribInternalError):
"""Invalid iterator id."""
class InvalidIndexError(GribInternalError):
"""Invalid index id."""
class InvalidGribError(GribInternalError):
"""Invalid grib id."""
class InvalidFileError(GribInternalError):
"""Invalid file id."""
class WrongStepUnitError(GribInternalError):
"""Wrong units for step (step must be integer)."""
class WrongStepError(GribInternalError):
"""Unable to set step."""
class InvalidTypeError(GribInternalError):
"""Invalid key type."""
class WrongLengthError(GribInternalError):
"""Wrong message length."""
class ValueCannotBeMissingError(GribInternalError):
"""Value cannot be missing."""
class InvalidSectionNumberError(GribInternalError):
"""Invalid section number."""
class NullHandleError(GribInternalError):
"""Null handle."""
class InvalidArgumentError(GribInternalError):
"""Invalid argument."""
class ReadOnlyError(GribInternalError):
"""Value is read only."""
class MemoryAllocationError(GribInternalError):
"""Memory allocation error."""
class GeocalculusError(GribInternalError):
"""Problem with calculation of geographic attributes."""
class NoMoreInSetError(GribInternalError):
"""Code cannot unpack because of string too small."""
class EncodingError(GribInternalError):
"""Encoding invalid."""
class DecodingError(GribInternalError):
"""Decoding invalid."""
class MessageInvalidError(GribInternalError):
"""Message invalid."""
class IOProblemError(GribInternalError):
"""Input output problem."""
class KeyValueNotFoundError(GribInternalError):
"""Key/value not found."""
class WrongArraySizeError(GribInternalError):
"""Array size mismatch."""
class CodeNotFoundInTableError(GribInternalError):
"""Code not found in code table."""
class FileNotFoundError(GribInternalError):
"""File not found."""
class ArrayTooSmallError(GribInternalError):
"""Passed array is too small."""
class MessageEndNotFoundError(GribInternalError):
"""Missing 7777 at end of message."""
class FunctionNotImplementedError(GribInternalError):
"""Function not yet implemented."""
class BufferTooSmallError(GribInternalError):
"""Passed buffer is too small."""
class InternalError(GribInternalError):
"""Internal error."""
class EndOfFileError(GribInternalError):
"""End of resource reached."""
ERROR_MAP = {
-67: FunctionalityNotEnabledError,
-66: WrongBitmapSizeError,
-65: OutOfRangeError,
-64: UnsupportedEditionError,
-63: AttributeNotFoundError,
-62: TooManyAttributesError,
-61: AttributeClashError,
-60: NullPointerError,
-59: MissingBufrEntryError,
-58: WrongConversionError,
-57: StringTooSmallError,
-56: InvalidKeyValueError,
-55: ValueDifferentError,
-54: DifferentEditionError,
-53: InvalidBitsPerValueError,
-52: CorruptedIndexError,
-51: MessageMalformedError,
-50: UnderflowError,
-49: SwitchNoMatchError,
-48: ConstantFieldError,
-47: MessageTooLargeError,
-46: InternalArrayTooSmallError,
-45: PrematureEndOfFileError,
-44: NullIndexError,
-43: EndOfIndexError,
-42: WrongGridError,
-41: NoValuesError,
-40: EndError,
-39: WrongTypeError,
-38: NoDefinitionsError,
-37: HashArrayNoMatchError,
-36: ConceptNoMatchError,
-35: OutOfAreaError,
-34: MissingKeyError,
-33: InvalidOrderByError,
-32: InvalidNearestError,
-31: InvalidKeysIteratorError,
-30: InvalidIteratorError,
-29: InvalidIndexError,
-28: InvalidGribError,
-27: InvalidFileError,
-26: WrongStepUnitError,
-25: WrongStepError,
-24: InvalidTypeError,
-23: WrongLengthError,
-22: ValueCannotBeMissingError,
-21: InvalidSectionNumberError,
-20: NullHandleError,
-19: InvalidArgumentError,
-18: ReadOnlyError,
-17: MemoryAllocationError,
-16: GeocalculusError,
-15: NoMoreInSetError,
-14: EncodingError,
-13: DecodingError,
-12: MessageInvalidError,
-11: IOProblemError,
-10: KeyValueNotFoundError,
-9: WrongArraySizeError,
-8: CodeNotFoundInTableError,
-7: FileNotFoundError,
-6: ArrayTooSmallError,
-5: MessageEndNotFoundError,
-4: FunctionNotImplementedError,
-3: BufferTooSmallError,
-2: InternalError,
-1: EndOfFileError,
}
def raise_grib_error(errid):
"""
Raise the GribInternalError corresponding to ``errid``.
"""
raise ERROR_MAP[errid](errid)