ESQL: Fail with 500 not 400 for ValueExtractor bugs (#126296)

In case of wrong layouts of ESQL's operators, it can happen that
ValueExtractor.extractorFor encounters a data type mismatch. Currently,
this throws IllegalArgumentException, which is treated like a user
exception and triggers a 400 response.

We need to return a 500 status code for such errors; this is also
important for observability of ES clusters, which can normally use 500
responses as an indicator of a bug.

Throw IllegalStateException instead, it's close enough.
This commit is contained in:
Alexander Spies 2025-04-07 11:21:57 +02:00 committed by GitHub
parent f8b99258f4
commit a152b4e29b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View file

@ -0,0 +1,5 @@
pr: 126296
summary: Fail with 500 not 400 for `ValueExtractor` bugs
area: ES|QL
type: bug
issues: []

View file

@ -27,7 +27,10 @@ interface ValueExtractor {
static ValueExtractor extractorFor(ElementType elementType, TopNEncoder encoder, boolean inKey, Block block) {
if (false == (elementType == block.elementType() || ElementType.NULL == block.elementType())) {
throw new IllegalArgumentException("Expected [" + elementType + "] but was [" + block.elementType() + "]");
// While this maybe should be an IllegalArgumentException, it's important to throw an exception that causes a 500 response.
// If we reach here, that's a bug. Arguably, the operators are in an illegal state because the layout doesn't match the
// actual pages.
throw new IllegalStateException("Expected [" + elementType + "] but was [" + block.elementType() + "]");
}
return switch (block.elementType()) {
case BOOLEAN -> ValueExtractorForBoolean.extractorFor(encoder, inKey, (BooleanBlock) block);