Skip to content
Merged
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 @@ -24,6 +24,7 @@
import org.elasticsearch.xpack.esql.telemetry.PlanTelemetry;

import java.util.BitSet;
import java.util.EmptyStackException;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Function;
Expand Down Expand Up @@ -153,6 +154,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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately exception is very generic and does not bring any details on position,
however I wonder if we could make any assumptions as for what went wrong here?

It might be frustrating to see message like this for not too complex query like:

                stats
                min = min(a),
                max = max(a)) WHERE (a % 3 > 10 OR a / 2 > 100),
                avg = avg(a) WHERE a / 2 > 100
                BY a

note max(a)).

We know this could be caused by extra ) or ]. I wonder if we should attempt to count them in here to highlight this could be an issue?

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3937,4 +3937,11 @@ public void testInvalidDoubleParamsType() {
);
}
}

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