File: errors.py

package info (click to toggle)
eccodes 2.12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 480,184 kB
  • sloc: ansic: 163,815; makefile: 21,266; sh: 8,507; python: 6,026; f90: 5,762; perl: 2,891; yacc: 818; lex: 356; cpp: 305; fortran: 116; awk: 66
file content (235 lines) | stat: -rw-r--r-- 8,148 bytes parent folder | download | duplicates (2)
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
"""
Exception class hierarchy
"""

from . import gribapi_swig as _internal


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:
            err, self.msg = _internal.grib_c_get_error_string(value, 1024)
            assert err == 0
        else:
            self.msg = value

    def __str__(self):
        return self.msg


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 = {
    -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)