Skip to content

Commit a824bb2

Browse files
authored
[8.x] ESQL: Catch parsing exception (elastic#124958) (elastic#124983)
* 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 * Update StatementParserTests.java Fix test for 8.x branch
1 parent 3e71db6 commit a824bb2

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;
@@ -112,6 +113,9 @@ private <T> T invokeParser(
112113
return result.apply(new AstBuilder(new ExpressionBuilder.ParsingContext(params, metrics)), tree);
113114
} catch (StackOverflowError e) {
114115
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);
115119
}
116120
}
117121

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
@@ -3751,4 +3751,11 @@ public void testInvalidDoubleParamsType() {
37513751
);
37523752
}
37533753
}
3754+
3755+
public void testUnclosedParenthesis() {
3756+
String[] queries = { "row ]", "from source | eval x = [1,2,3]]" };
3757+
for (String q : queries) {
3758+
expectError(q, "Invalid query");
3759+
}
3760+
}
37543761
}

0 commit comments

Comments
 (0)