Skip to content

Commit dc15462

Browse files
authored
ESQL: Catch parsing exception (#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 #119025
1 parent e8533c1 commit dc15462

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

2626
import java.util.BitSet;
27+
import java.util.EmptyStackException;
2728
import java.util.Map;
2829
import java.util.function.BiFunction;
2930
import java.util.function.Function;
@@ -153,6 +154,9 @@ private <T> T invokeParser(
153154
return result.apply(new AstBuilder(new ExpressionBuilder.ParsingContext(params, metrics)), tree);
154155
} catch (StackOverflowError e) {
155156
throw new ParsingException("ESQL statement is too large, causing stack overflow when generating the parsing tree: [{}]", query);
157+
// likely thrown by an invalid popMode (such as extra closing parenthesis)
158+
} catch (EmptyStackException ese) {
159+
throw new ParsingException("Invalid query [{}]", query);
156160
}
157161
}
158162

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
@@ -3937,4 +3937,11 @@ public void testInvalidDoubleParamsType() {
39373937
);
39383938
}
39393939
}
3940+
3941+
public void testUnclosedParenthesis() {
3942+
String[] queries = { "row a = )", "row ]", "from source | eval x = [1,2,3]]" };
3943+
for (String q : queries) {
3944+
expectError(q, "Invalid query");
3945+
}
3946+
}
39403947
}

0 commit comments

Comments
 (0)