Skip to content

Commit 463afba

Browse files
committed
Use FormatUnsuitable instead of FileTypeInvalid
Open-EO/openeo-api#505
1 parent ab2ad96 commit 463afba

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

openeo_driver/ProcessGraphDeserializer.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,15 @@
4545
from openeo_driver.datastructs import SarBackscatterArgs, ResolutionMergeArgs
4646
from openeo_driver.delayed_vector import DelayedVector
4747
from openeo_driver.dry_run import DryRunDataTracer, SourceConstraint
48-
from openeo_driver.errors import ProcessParameterRequiredException, ProcessParameterInvalidException, \
49-
FeatureUnsupportedException, OpenEOApiException, ProcessGraphInvalidException, FileTypeInvalidException, \
50-
ProcessUnsupportedException, CollectionNotFoundException
48+
from openeo_driver.errors import (
49+
ProcessParameterRequiredException,
50+
ProcessParameterInvalidException,
51+
FeatureUnsupportedException,
52+
OpenEOApiException,
53+
ProcessGraphInvalidException,
54+
ProcessUnsupportedException,
55+
CollectionNotFoundException,
56+
)
5157
from openeo_driver.processes import ProcessRegistry, ProcessSpec, DEFAULT_NAMESPACE, ProcessArgs
5258
from openeo_driver.save_result import JSONResult, SaveResult, AggregatePolygonResult, NullResult, \
5359
to_save_result, AggregatePolygonSpatialResult, MlModelResult

openeo_driver/processes.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from typing import Any, Callable, Collection, Dict, List, Optional, Tuple, Union
77

88
from openeo_driver.errors import (
9-
FileTypeInvalidException,
109
OpenEOApiException,
1110
ProcessParameterInvalidException,
1211
ProcessParameterRequiredException,
@@ -458,7 +457,11 @@ def validator_file_format(formats: Union[List[str], Dict[str, dict]]):
458457

459458
def validator(value: str):
460459
if value.lower() not in options:
461-
raise FileTypeInvalidException(type=value, types=", ".join(formats))
460+
raise OpenEOApiException(
461+
message=f"Invalid file format {value!r}. Allowed formats: {', '.join(formats)}",
462+
code="FormatUnsuitable",
463+
status_code=400,
464+
)
462465
return True
463466

464467
return validator

openeo_driver/util/ioformats.py

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
"""
55
from typing import Optional, Iterable, Dict
66

7-
from openeo_driver.errors import FileTypeInvalidException
8-
97

108
class FormatInfo:
119
"""Simple container of input/output format information: format code, mimetype, ..."""

tests/test_processes.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from openeo_driver.datacube import DriverDataCube
66
from openeo_driver.errors import (
77
FileTypeInvalidException,
8+
OpenEOApiException,
89
ProcessParameterInvalidException,
910
ProcessParameterRequiredException,
1011
ProcessUnsupportedException,
@@ -656,7 +657,9 @@ def test_validator_file_format(self, formats):
656657
assert args.get_required("format2", validator=validator) == "geojson"
657658

658659
with pytest.raises(
659-
FileTypeInvalidException,
660-
match=re.escape("File format TooExotic not allowed. Allowed file formats: GeoJSON, CSV"),
661-
):
660+
OpenEOApiException,
661+
match=re.escape("Invalid file format 'TooExotic'. Allowed formats: GeoJSON, CSV"),
662+
) as exc_info:
662663
_ = args.get_required("format3", validator=validator)
664+
665+
assert exc_info.value.code == "FormatUnsuitable"

0 commit comments

Comments
 (0)