Skip to content

Commit 75e9246

Browse files
authored
[8.17] ESQL: Catch parsing exception (elastic#124958) (elastic#124982)
* ESQL: Catch parsing exception (elastic#124958) When an invalid popMode occurs (due to an invalid query), ANTLR throws an out-of-channel exception, bypassing the existing checks. This PR extends the checks and properly reports the error back to the user Fix elastic#119025 (cherry picked from commit dc15462) # Conflicts: # x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlParser.java # x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java * Update StatementParserTests.java Fix test for 8.x branch
1 parent 14a97cd commit 75e9246

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

docs/changelog/124958.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 124958
2+
summary: Catch parsing exception
3+
area: ES|QL
4+
type: bug
5+
issues:
6+
- 119025

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/EsqlParser.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
2222

2323
import java.util.BitSet;
24+
import java.util.EmptyStackException;
2425
import java.util.function.BiFunction;
2526
import java.util.function.Function;
2627
import java.util.regex.Matcher;
@@ -91,6 +92,9 @@ private <T> T invokeParser(
9192
return result.apply(new AstBuilder(params), tree);
9293
} catch (StackOverflowError e) {
9394
throw new ParsingException("ESQL statement is too large, causing stack overflow when generating the parsing tree: [{}]", query);
95+
// likely thrown by an invalid popMode (such as extra closing parenthesis)
96+
} catch (EmptyStackException ese) {
97+
throw new ParsingException("Invalid query [{}]", query);
9498
}
9599
}
96100

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,4 +2346,11 @@ public void testInvalidMatchOperator() {
23462346
"line 1:37: mismatched input ':' expecting {<EOF>, '|', 'and', '::', 'or', '+', '-', '*', '/', '%'}"
23472347
);
23482348
}
2349+
2350+
public void testUnclosedParenthesis() {
2351+
String[] queries = { "row ]", "from source | eval x = [1,2,3]]" };
2352+
for (String q : queries) {
2353+
expectError(q, "Invalid query");
2354+
}
2355+
}
23492356
}

0 commit comments

Comments
 (0)