Skip to content

Commit

Permalink
Better error message when passing invalid geojson to validate_geojson…
Browse files Browse the repository at this point in the history
…_coordinates
  • Loading branch information
soxofaan committed Nov 16, 2023
1 parent 48db4a9 commit e3964a5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion openeo_driver/util/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from shapely.geometry import MultiPolygon, Polygon
from shapely.geometry.base import BaseGeometry

from openeo.util import repr_truncate
from openeo_driver.errors import OpenEOApiException
from openeo_driver.util.utm import auto_utm_epsg, auto_utm_epsg_for_geometry

Expand Down Expand Up @@ -78,7 +79,7 @@ def validate_geojson_basic(
return []


def validate_geojson_coordinates(geojson):
def validate_geojson_coordinates(geojson: dict):
def _validate_coordinates(coordinates, initial_run=True):
max_evaluations = 20
message = f"Failed to parse Geojson. Coordinates are invalid."
Expand Down Expand Up @@ -120,6 +121,11 @@ def _validate_feature_collection(geojson):
else:
_validate_coordinates(feature["geometry"]["coordinates"])

if not isinstance(geojson, dict):
raise ValueError(f"Invalid GeoJSON: not a dict: {repr_truncate(geojson)}")
if "type" not in geojson:
raise ValueError(f"Invalid GeoJSON: missing 'type' field: {repr_truncate(geojson)}")

if geojson["type"] == "Feature":
geojson = geojson["geometry"]

Expand Down

0 comments on commit e3964a5

Please sign in to comment.