Skip to content

Commit 99d985a

Browse files
committed
Do not let ShardBulkInferenceActionFilter unwrap / rewrap ESExceptions (elastic#123890)
* do not let ShardBulkInferenceActionFilter unwrap / rewrap ESExceptions
1 parent 1332412 commit 99d985a

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;
@@ -45,6 +44,7 @@
4544
import org.elasticsearch.xcontent.XContent;
4645
import org.elasticsearch.xpack.core.XPackField;
4746
import org.elasticsearch.xpack.core.inference.results.ChunkedInferenceError;
47+
import org.elasticsearch.xpack.inference.InferenceException;
4848
import org.elasticsearch.xpack.inference.mapper.SemanticTextField;
4949
import org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper;
5050
import org.elasticsearch.xpack.inference.mapper.SemanticTextUtils;
@@ -288,7 +288,7 @@ public void onFailure(Exception exc) {
288288
request.field
289289
);
290290
} else {
291-
failure = new ElasticsearchException(
291+
failure = new InferenceException(
292292
"Error loading inference for inference id [{}] on field [{}]",
293293
exc,
294294
inferenceId,
@@ -317,7 +317,7 @@ public void onResponse(List<ChunkedInference> results) {
317317
var acc = inferenceResults.get(request.index);
318318
if (result instanceof ChunkedInferenceError error) {
319319
acc.addFailure(
320-
new ElasticsearchException(
320+
new InferenceException(
321321
"Exception when running inference id [{}] on field [{}]",
322322
error.exception(),
323323
inferenceProvider.model.getInferenceEntityId(),
@@ -349,7 +349,7 @@ public void onFailure(Exception exc) {
349349
for (FieldInferenceRequest request : requests) {
350350
addInferenceResponseFailure(
351351
request.index,
352-
new ElasticsearchException(
352+
new InferenceException(
353353
"Exception when running inference id [{}] on field [{}]",
354354
exc,
355355
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
@@ -248,7 +248,9 @@ public void testItemFailures() throws Exception {
248248
assertNotNull(bulkShardRequest.items()[0].getPrimaryResponse());
249249
assertTrue(bulkShardRequest.items()[0].getPrimaryResponse().isFailed());
250250
BulkItemResponse.Failure failure = bulkShardRequest.items()[0].getPrimaryResponse().getFailure();
251+
assertThat(failure.getCause().getMessage(), containsString("Exception when running inference"));
251252
assertThat(failure.getCause().getCause().getMessage(), containsString("boom"));
253+
assertThat(failure.getStatus(), is(RestStatus.BAD_REQUEST));
252254

253255
// item 1 is a success
254256
assertNull(bulkShardRequest.items()[1].getPrimaryResponse());
@@ -267,7 +269,9 @@ public void testItemFailures() throws Exception {
267269
assertNotNull(bulkShardRequest.items()[2].getPrimaryResponse());
268270
assertTrue(bulkShardRequest.items()[2].getPrimaryResponse().isFailed());
269271
failure = bulkShardRequest.items()[2].getPrimaryResponse().getFailure();
272+
assertThat(failure.getCause().getMessage(), containsString("Exception when running inference"));
270273
assertThat(failure.getCause().getCause().getMessage(), containsString("boom"));
274+
assertThat(failure.getStatus(), is(RestStatus.BAD_REQUEST));
271275
} finally {
272276
chainExecuted.countDown();
273277
}

0 commit comments

Comments
 (0)