Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/124958.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 124958
summary: Catch parsing exception
area: ES|QL
type: bug
issues:
- 119025
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.elasticsearch.xpack.esql.telemetry.PlanTelemetry;

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2977,4 +2977,11 @@ public void testInvalidInsistAsterisk() {
expectError("FROM text | EVAL x = 4 | INSIST_🐔 *", "INSIST doesn't support wildcards, found [*]");
expectError("FROM text | EVAL x = 4 | INSIST_🐔 foo*", "INSIST doesn't support wildcards, found [foo*]");
}

public void testUnclosedParenthesis() {
String[] queries = { "row a = )", "row ]", "from source | eval x = [1,2,3]]" };
for (String q : queries) {
expectError(q, "Invalid query");
}
}
}