Skip to content

Commit c14ccdb

Browse files
Mikep86tteofili
andauthored
[8.16] Do not let ShardBulkInferenceActionFilter unwrap / rewrap ESExceptions (#123890) (#124359)
* Do not let ShardBulkInferenceActionFilter unwrap / rewrap ESExceptions (#123890) * do not let ShardBulkInferenceActionFilter unwrap / rewrap ESExceptions (cherry picked from commit 74bb0f9) # Conflicts: # x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/filter/ShardBulkInferenceActionFilter.java * Add missing import --------- Co-authored-by: Tommaso Teofili <[email protected]>
1 parent a13ad87 commit c14ccdb

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-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;
@@ -39,6 +38,7 @@
3938
import org.elasticsearch.rest.RestStatus;
4039
import org.elasticsearch.tasks.Task;
4140
import org.elasticsearch.xpack.core.inference.results.ErrorChunkedInferenceResults;
41+
import org.elasticsearch.xpack.inference.InferenceException;
4242
import org.elasticsearch.xpack.inference.mapper.SemanticTextField;
4343
import org.elasticsearch.xpack.inference.mapper.SemanticTextFieldMapper;
4444
import org.elasticsearch.xpack.inference.registry.ModelRegistry;
@@ -255,7 +255,7 @@ public void onFailure(Exception exc) {
255255
request.field
256256
);
257257
} else {
258-
failure = new ElasticsearchException(
258+
failure = new InferenceException(
259259
"Error loading inference for inference id [{}] on field [{}]",
260260
exc,
261261
inferenceId,
@@ -284,7 +284,7 @@ public void onResponse(List<ChunkedInferenceServiceResults> results) {
284284
var acc = inferenceResults.get(request.index);
285285
if (result instanceof ErrorChunkedInferenceResults error) {
286286
acc.addFailure(
287-
new ElasticsearchException(
287+
new InferenceException(
288288
"Exception when running inference id [{}] on field [{}]",
289289
error.getException(),
290290
inferenceProvider.model.getInferenceEntityId(),
@@ -315,7 +315,7 @@ public void onFailure(Exception exc) {
315315
for (FieldInferenceRequest request : requests) {
316316
addInferenceResponseFailure(
317317
request.index,
318-
new ElasticsearchException(
318+
new InferenceException(
319319
"Exception when running inference id [{}] on field [{}]",
320320
exc,
321321
inferenceProvider.model.getInferenceEntityId(),

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import static org.hamcrest.Matchers.containsString;
6666
import static org.hamcrest.Matchers.equalTo;
6767
import static org.hamcrest.Matchers.instanceOf;
68+
import static org.hamcrest.Matchers.is;
6869
import static org.mockito.Mockito.any;
6970
import static org.mockito.Mockito.doAnswer;
7071
import static org.mockito.Mockito.mock;
@@ -173,7 +174,9 @@ public void testItemFailures() throws Exception {
173174
assertNotNull(bulkShardRequest.items()[0].getPrimaryResponse());
174175
assertTrue(bulkShardRequest.items()[0].getPrimaryResponse().isFailed());
175176
BulkItemResponse.Failure failure = bulkShardRequest.items()[0].getPrimaryResponse().getFailure();
177+
assertThat(failure.getCause().getMessage(), containsString("Exception when running inference"));
176178
assertThat(failure.getCause().getCause().getMessage(), containsString("boom"));
179+
assertThat(failure.getStatus(), is(RestStatus.BAD_REQUEST));
177180

178181
// item 1 is a success
179182
assertNull(bulkShardRequest.items()[1].getPrimaryResponse());
@@ -184,7 +187,9 @@ public void testItemFailures() throws Exception {
184187
assertNotNull(bulkShardRequest.items()[2].getPrimaryResponse());
185188
assertTrue(bulkShardRequest.items()[2].getPrimaryResponse().isFailed());
186189
failure = bulkShardRequest.items()[2].getPrimaryResponse().getFailure();
190+
assertThat(failure.getCause().getMessage(), containsString("Exception when running inference"));
187191
assertThat(failure.getCause().getCause().getMessage(), containsString("boom"));
192+
assertThat(failure.getStatus(), is(RestStatus.BAD_REQUEST));
188193
} finally {
189194
chainExecuted.countDown();
190195
}

0 commit comments

Comments
 (0)