Skip to content

Commit

Permalink
Avoid throwing generic Exceptions
Browse files Browse the repository at this point in the history
and exception chaining where appropriate
  • Loading branch information
soxofaan committed Jan 19, 2024
1 parent 8e5ba7f commit 9bab024
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/openeo_test_suite/lib/process_runner/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ def encode_labeled_array(self, data: Dict) -> Any:
to the internal backend representation openEO process tests.
specification -> backend
"""
raise Exception("labeled arrays not implemented yet")
raise NotImplementedError("labeled arrays not implemented yet")

def encode_datacube(self, data: Dict) -> Any:
"""
Converts a datacube from the JSON object representation (type: datacube) to the
internal backend representation openEO process tests.
specification -> backend
"""
raise Exception("datacubes not implemented yet")
raise NotImplementedError("datacubes not implemented yet")

def encode_data(self, data: Any) -> Any:
"""
Expand Down
2 changes: 1 addition & 1 deletion src/openeo_test_suite/lib/process_runner/dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def encode_data(self, data):
try:
return BoundingBox(**data)
except Exception as e:
raise Exception("Failed to parse bounding box: {}".format(str(e)))
raise ValueError("Failed to encode bounding box") from e

return data

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def validate_stac_dict(collection_dict: dict):
stac = stac_validator.StacValidate()
is_valid_stac = stac.validate_dict(collection_dict)
if not is_valid_stac:
raise Exception(stac.message)
raise ValueError(stac.message)


def test_get_collections(connection):
Expand Down
10 changes: 4 additions & 6 deletions src/openeo_test_suite/tests/processes/processing/test_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,17 @@ def load_ref(ref, file):
with open(path) as f:
return f.read()
else:
raise Exception(
"External references to files with the given extension not implemented yet."
)
raise NotImplementedError(f"Unhandled external reference {ref}.")
except Exception as e:
raise Exception("Failed to load external reference {}: {}".format(ref, e))
raise RuntimeError(f"Failed to load external reference {ref}") from e


def check_non_json_values(value):
if isinstance(value, float):
if math.isnan(value):
raise Exception("HTTP JSON APIs don't support NaN values")
raise ValueError("HTTP JSON APIs don't support NaN values")
elif math.isinf(value):
raise Exception("HTTP JSON APIs don't support infinity values")
raise ValueError("HTTP JSON APIs don't support infinity values")
elif isinstance(value, dict):
for key in value:
check_non_json_values(value[key])
Expand Down

0 comments on commit 9bab024

Please sign in to comment.