Skip to content

Commit 2f48b83

Browse files
committed
Raise the correct exceptions
1 parent 5b3367e commit 2f48b83

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

Diff for: gribapi/errors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ class InvalidIndexError(GribInternalError):
192192

193193

194194
class InvalidGribError(GribInternalError):
195-
"""Invalid grib id."""
195+
"""Invalid GRIB id."""
196196

197197

198198
class InvalidFileError(GribInternalError):

Diff for: gribapi/gribapi.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ def wrapper(*args):
162162
def get_handle(msgid):
163163
h = ffi.cast("grib_handle*", msgid)
164164
if h == ffi.NULL:
165-
raise errors.InvalidGribError(f"get_handle: Bad message ID {msgid}")
165+
raise errors.NullHandleError(f"get_handle: Bad message ID {msgid}")
166166
return h
167167

168168

169169
def put_handle(handle):
170170
if handle == ffi.NULL:
171-
raise errors.InvalidGribError(f"put_handle: Bad message ID {handle}")
171+
raise errors.NullHandleError(f"put_handle: Bad message ID {handle}")
172172
return int(ffi.cast("size_t", handle))
173173

174174

@@ -1137,7 +1137,7 @@ def grib_clone(msgid_src):
11371137
h_src = get_handle(msgid_src)
11381138
h_dest = lib.grib_handle_clone(h_src)
11391139
if h_dest == ffi.NULL:
1140-
raise errors.InvalidGribError("clone failed")
1140+
raise errors.MessageInvalidError("clone failed")
11411141
return put_handle(h_dest)
11421142

11431143

@@ -2381,7 +2381,7 @@ def grib_new_from_message(message):
23812381
message = message.encode(ENC)
23822382
h = lib.grib_handle_new_from_message_copy(ffi.NULL, message, len(message))
23832383
if h == ffi.NULL:
2384-
raise errors.InvalidGribError("new_from_message failed")
2384+
raise errors.MessageInvalidError("new_from_message failed")
23852385
return put_handle(h)
23862386

23872387

Diff for: tests/test_eccodes.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def test_codes_get_native_type():
8484
assert eccodes.codes_get_native_type(gid, "referenceValue") is float
8585
assert eccodes.codes_get_native_type(gid, "stepType") is str
8686
assert eccodes.codes_get_native_type(gid, "section_1") is None
87-
with pytest.raises(eccodes.InvalidGribError):
88-
eccodes.codes_get_native_type(0, "aKey")
87+
with pytest.raises(eccodes.NullHandleError):
88+
eccodes.codes_get_native_type(0, "aKey") # NULL handle
8989

9090

9191
def test_new_from_file():

0 commit comments

Comments
 (0)