Skip to content

[9.0] ESQL: Catch parsing exception (#124958) #124980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 9.0
Choose a base branch
from
Open
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");
}
}
}