Skip to content

Commit

Permalink
Use ValueError rather than plain Exception
Browse files Browse the repository at this point in the history
  • Loading branch information
shahramn committed Nov 28, 2020
1 parent 6ef0a3e commit 3dd337a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions gribapi/gribapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def codes_new_from_file(fileobj, product_kind, headers_only=False):
return gts_new_from_file(fileobj, headers_only)
if product_kind == CODES_PRODUCT_ANY:
return any_new_from_file(fileobj, headers_only)
raise Exception("Invalid product kind: " + str(product_kind))
raise ValueError("Invalid product kind %d" % product_kind)


@require(fileobj=file)
Expand Down Expand Up @@ -1031,7 +1031,7 @@ def codes_new_from_samples(samplename, product_kind):
return grib_new_from_samples(samplename)
if product_kind == CODES_PRODUCT_BUFR:
return codes_bufr_new_from_samples(samplename)
raise Exception("Invalid product kind: " + str(product_kind))
raise ValueError("Invalid product kind %d" % product_kind)


@require(samplename=str)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_eccodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_new_from_file():
with open(fpath, "rb") as f:
msgid = codes_new_from_file(f, CODES_PRODUCT_METAR)
assert msgid is None
with pytest.raises(Exception):
with pytest.raises(ValueError):
with open(fpath, "rb") as f:
codes_new_from_file(f, 1024)

Expand Down Expand Up @@ -581,7 +581,7 @@ def test_bufr_multi_element_constant_arrays():
def test_bufr_new_from_samples_error():
with pytest.raises(FileNotFoundError):
gid = codes_new_from_samples("nonExistentSample", CODES_PRODUCT_BUFR)
with pytest.raises(Exception):
with pytest.raises(ValueError):
codes_new_from_samples("BUFR3_local", 1024)


Expand Down

0 comments on commit 3dd337a

Please sign in to comment.