Skip to content

Commit 74bb0f9

Browse files
authored
Do not let ShardBulkInferenceActionFilter unwrap / rewrap ESExceptions (#123890)
* do not let ShardBulkInferenceActionFilter unwrap / rewrap ESExceptions
1 parent 02f01af commit 74bb0f9

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

docs/changelog/123890.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 123890
2+
summary: Do not let `ShardBulkInferenceActionFilter` unwrap / rewrap ESExceptions
3+
area: Search
4+
type: bug
5+
issues: []
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.inference;
9+
10+
import org.elasticsearch.ElasticsearchException;
11+
import org.elasticsearch.ElasticsearchWrapperException;
12+
13+
public class InferenceException extends ElasticsearchException implements ElasticsearchWrapperException {
14+
public InferenceException(String message, Throwable cause, Object... args) {
15+
super(message, cause, args);
16+
}
17+
18+
}

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/filter/ShardBulkInferenceActionFilter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
package org.elasticsearch.xpack.inference.action.filter;
99

10-
import org.elasticsearch.ElasticsearchException;
1110
import org.elasticsearch.ElasticsearchStatusException;
1211
import org.elasticsearch.ExceptionsHelper;
1312
import org.elasticsearch.ResourceNotFoundException;
@@ -46,6 +45,7 @@
4645
import org.elasticsearch.xcontent.XContent;
4746
import org.elasticsearch.xpack.core.XPackField;
4847
import org.elasticsearch.xpack.core.inference.results.ChunkedInferenceError;
48+
import org.elasticsearch.xpack.inference.InferenceException;
4949
import org.elasticsearch.xpack.inference.mapper.SemanticTextField;
5050
import org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper;
5151
import org.elasticsearch.xpack.inference.mapper.SemanticTextUtils;
@@ -290,7 +290,7 @@ public void onFailure(Exception exc) {
290290
request.field
291291
);
292292
} else {
293-
failure = new ElasticsearchException(
293+
failure = new InferenceException(
294294
"Error loading inference for inference id [{}] on field [{}]",
295295
exc,
296296
inferenceId,
@@ -319,7 +319,7 @@ public void onResponse(List<ChunkedInference> results) {
319319
var acc = inferenceResults.get(request.index);
320320
if (result instanceof ChunkedInferenceError error) {
321321
acc.addFailure(
322-
new ElasticsearchException(
322+
new InferenceException(
323323
"Exception when running inference id [{}] on field [{}]",
324324
error.exception(),
325325
inferenceProvider.model.getInferenceEntityId(),
@@ -351,7 +351,7 @@ public void onFailure(Exception exc) {
351351
for (FieldInferenceRequest request : requests) {
352352
addInferenceResponseFailure(
353353
request.index,
354-
new ElasticsearchException(
354+
new InferenceException(
355355
"Exception when running inference id [{}] on field [{}]",
356356
exc,
357357
inferenceProvider.model.getInferenceEntityId(),

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/action/filter/ShardBulkInferenceActionFilterTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ public void testItemFailures() throws Exception {
251251
assertNotNull(bulkShardRequest.items()[0].getPrimaryResponse());
252252
assertTrue(bulkShardRequest.items()[0].getPrimaryResponse().isFailed());
253253
BulkItemResponse.Failure failure = bulkShardRequest.items()[0].getPrimaryResponse().getFailure();
254+
assertThat(failure.getCause().getMessage(), containsString("Exception when running inference"));
254255
assertThat(failure.getCause().getCause().getMessage(), containsString("boom"));
256+
assertThat(failure.getStatus(), is(RestStatus.BAD_REQUEST));
255257

256258
// item 1 is a success
257259
assertNull(bulkShardRequest.items()[1].getPrimaryResponse());
@@ -270,7 +272,9 @@ public void testItemFailures() throws Exception {
270272
assertNotNull(bulkShardRequest.items()[2].getPrimaryResponse());
271273
assertTrue(bulkShardRequest.items()[2].getPrimaryResponse().isFailed());
272274
failure = bulkShardRequest.items()[2].getPrimaryResponse().getFailure();
275+
assertThat(failure.getCause().getMessage(), containsString("Exception when running inference"));
273276
assertThat(failure.getCause().getCause().getMessage(), containsString("boom"));
277+
assertThat(failure.getStatus(), is(RestStatus.BAD_REQUEST));
274278
} finally {
275279
chainExecuted.countDown();
276280
}

0 commit comments

Comments
 (0)