{"record":{"id":"b240439f46c58ac9","repo":"elastic/elasticsearch","slug":"expected-or-but-found","errorCode":null,"errorMessage":"expected , or ) but found: {}","messagePattern":"expected , or \\) but found: (.+?)","errorType":"validation","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"libs/geo/src/main/java/org/elasticsearch/geometry/utils/WellKnownText.java","lineNumber":780,"sourceCode":"        if (nextWord(stream).equals(COMMA)) {\n            return COMMA;\n        }\n        throw new ParseException(\"expected \" + COMMA + \" but found: \" + tokenString(stream), stream.lineno());\n    }\n\n    static String nextOpener(StreamTokenizer stream) throws IOException, ParseException {\n        if (nextWord(stream).equals(LPAREN)) {\n            return LPAREN;\n        }\n        throw new ParseException(\"expected \" + LPAREN + \" but found: \" + tokenString(stream), stream.lineno());\n    }\n\n    static String nextCloserOrComma(StreamTokenizer stream) throws IOException, ParseException {\n        String token = nextWord(stream);\n        if (token.equals(COMMA) || token.equals(RPAREN)) {\n            return token;\n        }\n        throw new ParseException(\"expected \" + COMMA + \" or \" + RPAREN + \" but found: \" + tokenString(stream), stream.lineno());\n    }\n\n    private static String getWKTName(Geometry geometry) {\n        return geometry.visit(new GeometryVisitor<String, RuntimeException>() {\n            @Override\n            public String visit(Circle circle) {\n                return \"CIRCLE\";\n            }\n\n            @Override\n            public String visit(GeometryCollection<?> collection) {\n                return \"GEOMETRYCOLLECTION\";\n            }\n\n            @Override\n            public String visit(Line line) {\n                return \"LINESTRING\";\n            }","sourceCodeStart":762,"sourceCodeEnd":798,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/geo/src/main/java/org/elasticsearch/geometry/utils/WellKnownText.java#L762-L798","documentation":"Thrown by WellKnownText.nextCloserOrComma when the token is neither ',' nor ')'. This helper is used to iterate over a list of sub-elements (vertices, rings, or collection members): it accepts a comma to continue the list or ')' to terminate it.","triggerScenarios":"After reading an element in a list, the parser expects either a comma (more elements) or a closing paren (end of list). If it finds anything else (a keyword, EOF, a number, a stray symbol), it throws. Example: \"LINESTRING (0 0, 1 1 x)\" where 'x' appears where , or ) is expected.","commonSituations":"Stray characters in coordinate lists; truncated WKT mid-list; a tokenizer desynchronized by a prior malformed token; non-WKT content embedded in the string.","solutions":["Inspect the token at stream.lineno() and ensure the position holds either ',' (continue list) or ')' (end list).","Remove stray characters and confirm the list grammar is well-formed.","If iterating a collection, ensure each member is a complete geometry followed by , or )."],"exampleFix":"// before: stray 'x' after a vertex where , or ) expected\nGeometry g = WellKnownText.fromWKT(\"LINESTRING (0 0, 1 1 x)\");\n\n// after: proper separator or closer\nGeometry g = WellKnownText.fromWKT(\"LINESTRING (0 0, 1 1)\");\n// or continue the list\nGeometry g = WellKnownText.fromWKT(\"LINESTRING (0 0, 1 1, 2 2)\");","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    Geometry g = WellKnownText.fromWKT(wkt);\n} catch (java.text.ParseException e) {\n    if (e.getMessage().contains(\"expected , or )\")) {\n        // stray token in a coordinate/element list\n    }\n    throw e;\n}","preventionTips":["Ensure each list element is followed by , or ).","Remove stray characters and non-WKT content from coordinate lists."],"tags":["geo","wkt","parsing","elasticsearch","geometry"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T11:17:21.771Z"}