Skip to content

Commit 2fa9da6

Browse files
committed
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
1 parent 0c7ccb6 commit 2fa9da6

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-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: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import org.elasticsearch.xpack.esql.telemetry.PlanTelemetry;
2424

2525
import java.util.BitSet;
26+
import java.util.EmptyStackException;
27+
import java.util.Map;
2628
import java.util.function.BiFunction;
2729
import java.util.function.Function;
2830
import java.util.regex.Matcher;
@@ -111,6 +113,9 @@ private <T> T invokeParser(
111113
return result.apply(new AstBuilder(new ExpressionBuilder.ParsingContext(params, metrics)), tree);
112114
} catch (StackOverflowError e) {
113115
throw new ParsingException("ESQL statement is too large, causing stack overflow when generating the parsing tree: [{}]", query);
116+
// likely thrown by an invalid popMode (such as extra closing parenthesis)
117+
} catch (EmptyStackException ese) {
118+
throw new ParsingException("Invalid query [{}]", query);
114119
}
115120
}
116121

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
@@ -2977,4 +2977,11 @@ public void testInvalidInsistAsterisk() {
29772977
expectError("FROM text | EVAL x = 4 | INSIST_🐔 *", "INSIST doesn't support wildcards, found [*]");
29782978
expectError("FROM text | EVAL x = 4 | INSIST_🐔 foo*", "INSIST doesn't support wildcards, found [foo*]");
29792979
}
2980+
2981+
public void testUnclosedParenthesis() {
2982+
String[] queries = { "row a = )", "row ]", "from source | eval x = [1,2,3]]" };
2983+
for (String q : queries) {
2984+
expectError(q, "Invalid query");
2985+
}
2986+
}
29802987
}

0 commit comments

Comments
 (0)