{"record":{"id":"799e630d44b629ef","repo":"prestodb/presto","slug":"invalid-function-argument-799e63","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"Invalid GeoJSON: ","messagePattern":"Invalid GeoJSON: ","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"warning","filePath":"presto-geospatial-toolkit/src/main/java/com/facebook/presto/geospatial/GeometryUtils.java","lineNumber":248,"sourceCode":"        corners.add(new Point(envelope.getXMax(), envelope.getYMax()));\n\n        for (int i = 0; i < 4; i++) {\n            Point point = polygon.getPoint(i);\n            if (!corners.contains(point)) {\n                return false;\n            }\n        }\n\n        return true;\n    }\n\n    public static org.locationtech.jts.geom.Geometry jtsGeometryFromJson(String json)\n    {\n        try {\n            return new GeoJsonReader().read(json);\n        }\n        catch (ParseException | IllegalArgumentException e) {\n            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, \"Invalid GeoJSON: \" + e.getMessage(), e);\n        }\n    }\n\n    public static Optional<String> jsonFromJtsGeometry(org.locationtech.jts.geom.Geometry geometry)\n    {\n        if (ATOMIC_GEOMETRY_TYPES.contains(geometry.getGeometryType()) && geometry.isEmpty()) {\n            return Optional.empty();\n        }\n        else {\n            return Optional.of(new GeoJsonWriter().write(geometry));\n        }\n    }\n\n    public static org.locationtech.jts.geom.Geometry jtsGeometryFromWkt(String wkt)\n    {\n        try {\n            return new WKTReader(GEOMETRY_FACTORY).read(wkt);\n        }","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-geospatial-toolkit/src/main/java/com/facebook/presto/geospatial/GeometryUtils.java#L230-L266","documentation":"GeometryUtils.jtsGeometryFromJson parses a JSON string with GeoJsonReader and converts any ParseException or IllegalArgumentException into INVALID_FUNCTION_ARGUMENT with 'Invalid GeoJSON: <message>'. It signals that the supplied string is not parseable as GeoJSON.","triggerScenarios":"Passing malformed JSON, JSON that is valid but not GeoJSON (missing 'type'/'coordinates'), or unsupported geometry types to ST_GeomFromGeoJSON-style functions.","commonSituations":"Truncated JSON from a stream/ETL; using GeoJSON Feature/FeatureCollection where a bare geometry is required; coordinates with wrong nesting depth; single quotes or unquoted keys in hand-written JSON.","solutions":["Validate the JSON (e.g. jq or a JSON parser) and confirm it is a GeoJSON geometry object with proper 'type' and 'coordinates'.","Unwrap Feature/FeatureCollection to the underlying geometry before conversion.","Fix coordinate array nesting to match the geometry dimension (Point -> [x,y]; Polygon -> [[ [x,y], ... ]])."],"exampleFix":"// before\nSELECT ST_GeomFromGeoJSON('{\"type\": \"Point\", \"coordinates\": 1.0}');\n// after\nSELECT ST_GeomFromGeoJSON('{\"type\": \"Point\", \"coordinates\": [1.0, 2.0]}');","handlingStrategy":"validation","validationCode":"boolean isProbablyGeoJson(String s) {\n    try {\n        JsonNode n = MAPPER.readTree(s);\n        return n.has(\"type\") && n.has(\"coordinates\")\n            && List.of(\"Point\",\"MultiPoint\",\"LineString\",\"MultiLineString\",\"Polygon\",\"MultiPolygon\",\"GeometryCollection\")\n                   .contains(n.get(\"type\").asText());\n    } catch (Exception e) { return false; }\n}","typeGuard":"boolean isGeoJsonObject(String s) {\n    return s != null && s.trim().startsWith(\"{\") && s.contains(\"\\\"type\\\"\") && s.contains(\"\\\"coordinates\\\"\");\n}","tryCatchPattern":"try {\n    Geometry g = GeometryUtils.jtsGeometryFromJson(json);\n} catch (PrestoException e) {\n    if (e.getErrorCode().equals(INVALID_FUNCTION_ARGUMENT.toErrorCode())) {\n        // log e.getMessage() which includes the parser's reason, then fix input\n    }\n}","preventionTips":["Validate JSON with a parser and check for required 'type' and 'coordinates' fields.","Unwrap GeoJSON Feature/FeatureCollection to bare geometries before parsing.","Match coordinate array nesting depth to geometry dimension.","Round-trip test sample data through jsonFromJtsGeometry/jtsGeometryFromJson."],"tags":["geospatial","geojson","parsing","invalid-input"],"backgroundTag":"invalid-geojson","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}