mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-04-19 04:45:07 -04:00
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:
parent
f8b99258f4
commit
a152b4e29b
2 changed files with 9 additions and 1 deletions
5
docs/changelog/126296.yaml
Normal file
5
docs/changelog/126296.yaml
Normal file
|
@ -0,0 +1,5 @@
|
|||
pr: 126296
|
||||
summary: Fail with 500 not 400 for `ValueExtractor` bugs
|
||||
area: ES|QL
|
||||
type: bug
|
||||
issues: []
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue