Skip to content

Commit 3661cdc

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 4ac5dd1 commit 3661cdc

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
@@ -23,6 +23,7 @@
2323
import org.elasticsearch.xpack.esql.telemetry.PlanTelemetry;
2424

2525
import java.util.BitSet;
26+
import java.util.EmptyStackException;
2627
import java.util.function.BiFunction;
2728
import java.util.function.Function;
2829
import java.util.regex.Matcher;
@@ -111,6 +112,9 @@ private <T> T invokeParser(
111112
return result.apply(new AstBuilder(new ExpressionBuilder.ParsingContext(params, metrics)), tree);
112113
} catch (StackOverflowError e) {
113114
throw new ParsingException("ESQL statement is too large, causing stack overflow when generating the parsing tree: [{}]", query);
115+
// likely thrown by an invalid popMode (such as extra closing parenthesis)
116+
} catch (EmptyStackException ese) {
117+
throw new ParsingException("Invalid query [{}]", query);
114118
}
115119
}
116120

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
@@ -2966,4 +2966,11 @@ public void testInvalidJoinPatterns() {
29662966
);
29672967
}
29682968
}
2969+
2970+
public void testUnclosedParenthesis() {
2971+
String[] queries = { "row a = )", "row ]", "from source | eval x = [1,2,3]]" };
2972+
for (String q : queries) {
2973+
expectError(q, "Invalid query");
2974+
}
2975+
}
29692976
}

0 commit comments

Comments
 (0)