Skip to content

Commit

Permalink
Use FormatUnsuitable instead of FileTypeInvalid
Browse files Browse the repository at this point in the history
  • Loading branch information
soxofaan committed Aug 7, 2023
1 parent ab2ad96 commit 463afba
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
12 changes: 9 additions & 3 deletions openeo_driver/ProcessGraphDeserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@
from openeo_driver.datastructs import SarBackscatterArgs, ResolutionMergeArgs
from openeo_driver.delayed_vector import DelayedVector
from openeo_driver.dry_run import DryRunDataTracer, SourceConstraint
from openeo_driver.errors import ProcessParameterRequiredException, ProcessParameterInvalidException, \
FeatureUnsupportedException, OpenEOApiException, ProcessGraphInvalidException, FileTypeInvalidException, \
ProcessUnsupportedException, CollectionNotFoundException
from openeo_driver.errors import (
ProcessParameterRequiredException,
ProcessParameterInvalidException,
FeatureUnsupportedException,
OpenEOApiException,
ProcessGraphInvalidException,
ProcessUnsupportedException,
CollectionNotFoundException,
)
from openeo_driver.processes import ProcessRegistry, ProcessSpec, DEFAULT_NAMESPACE, ProcessArgs
from openeo_driver.save_result import JSONResult, SaveResult, AggregatePolygonResult, NullResult, \
to_save_result, AggregatePolygonSpatialResult, MlModelResult
Expand Down
7 changes: 5 additions & 2 deletions openeo_driver/processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from typing import Any, Callable, Collection, Dict, List, Optional, Tuple, Union

from openeo_driver.errors import (
FileTypeInvalidException,
OpenEOApiException,
ProcessParameterInvalidException,
ProcessParameterRequiredException,
Expand Down Expand Up @@ -458,7 +457,11 @@ def validator_file_format(formats: Union[List[str], Dict[str, dict]]):

def validator(value: str):
if value.lower() not in options:
raise FileTypeInvalidException(type=value, types=", ".join(formats))
raise OpenEOApiException(
message=f"Invalid file format {value!r}. Allowed formats: {', '.join(formats)}",
code="FormatUnsuitable",
status_code=400,
)
return True

return validator
Expand Down
2 changes: 0 additions & 2 deletions openeo_driver/util/ioformats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
"""
from typing import Optional, Iterable, Dict

from openeo_driver.errors import FileTypeInvalidException


class FormatInfo:
"""Simple container of input/output format information: format code, mimetype, ..."""
Expand Down
9 changes: 6 additions & 3 deletions tests/test_processes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from openeo_driver.datacube import DriverDataCube
from openeo_driver.errors import (
FileTypeInvalidException,
OpenEOApiException,
ProcessParameterInvalidException,
ProcessParameterRequiredException,
ProcessUnsupportedException,
Expand Down Expand Up @@ -656,7 +657,9 @@ def test_validator_file_format(self, formats):
assert args.get_required("format2", validator=validator) == "geojson"

with pytest.raises(
FileTypeInvalidException,
match=re.escape("File format TooExotic not allowed. Allowed file formats: GeoJSON, CSV"),
):
OpenEOApiException,
match=re.escape("Invalid file format 'TooExotic'. Allowed formats: GeoJSON, CSV"),
) as exc_info:
_ = args.get_required("format3", validator=validator)

assert exc_info.value.code == "FormatUnsuitable"

0 comments on commit 463afba

Please sign in to comment.