Skip to content

Commit e3964a5

Browse files
committed
Better error message when passing invalid geojson to validate_geojson_coordinates
1 parent 48db4a9 commit e3964a5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

openeo_driver/util/geometry.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from shapely.geometry import MultiPolygon, Polygon
1212
from shapely.geometry.base import BaseGeometry
1313

14+
from openeo.util import repr_truncate
1415
from openeo_driver.errors import OpenEOApiException
1516
from openeo_driver.util.utm import auto_utm_epsg, auto_utm_epsg_for_geometry
1617

@@ -78,7 +79,7 @@ def validate_geojson_basic(
7879
return []
7980

8081

81-
def validate_geojson_coordinates(geojson):
82+
def validate_geojson_coordinates(geojson: dict):
8283
def _validate_coordinates(coordinates, initial_run=True):
8384
max_evaluations = 20
8485
message = f"Failed to parse Geojson. Coordinates are invalid."
@@ -120,6 +121,11 @@ def _validate_feature_collection(geojson):
120121
else:
121122
_validate_coordinates(feature["geometry"]["coordinates"])
122123

124+
if not isinstance(geojson, dict):
125+
raise ValueError(f"Invalid GeoJSON: not a dict: {repr_truncate(geojson)}")
126+
if "type" not in geojson:
127+
raise ValueError(f"Invalid GeoJSON: missing 'type' field: {repr_truncate(geojson)}")
128+
123129
if geojson["type"] == "Feature":
124130
geojson = geojson["geometry"]
125131

0 commit comments

Comments
 (0)