Skip to content

Commit a565b2d

Browse files
authored
Do not wrap ingest processor exception with IAE (#48816)
The problem with wrapping here is that it converts any exception into an IAE, which we treat as a client error (400 status) whereas the exception being wrapped here could be a server error (e.g., NPE). This commit stops wrapping all ingest processor exceptions as IAEs.
1 parent 0e548aa commit a565b2d

File tree

7 files changed

+10
-12
lines changed

7 files changed

+10
-12
lines changed

modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/210_pipeline_processor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,4 @@ teardown:
107107
pipeline: "outer"
108108
body: {}
109109
- match: { error.root_cause.0.type: "exception" }
110-
- match: { error.root_cause.0.reason: "java.lang.IllegalArgumentException: java.lang.IllegalStateException: Cycle detected for pipeline: inner" }
110+
- match: { error.root_cause.0.reason: "java.lang.IllegalStateException: Cycle detected for pipeline: inner" }

modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/90_simulate.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,8 +653,8 @@ teardown:
653653
}
654654
- length: { docs: 1 }
655655
- length: { docs.0.processor_results: 1 }
656-
- match: { docs.0.processor_results.0.error.reason: "java.lang.IllegalArgumentException: java.lang.IllegalStateException: Cycle detected for pipeline: outer" }
657-
- match: { docs.0.processor_results.0.error.caused_by.caused_by.reason: "Cycle detected for pipeline: outer" }
656+
- match: { docs.0.processor_results.0.error.reason: "java.lang.IllegalStateException: Cycle detected for pipeline: outer" }
657+
- match: { docs.0.processor_results.0.error.caused_by.reason: "Cycle detected for pipeline: outer" }
658658

659659
---
660660
"Test verbose simulate with Pipeline Processor with Multiple Pipelines":

server/src/main/java/org/elasticsearch/ingest/CompoundProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ private ElasticsearchException newCompoundProcessorException(Exception e, String
212212
return (ElasticsearchException) e;
213213
}
214214

215-
ElasticsearchException exception = new ElasticsearchException(new IllegalArgumentException(e));
215+
ElasticsearchException exception = new ElasticsearchException(e);
216216

217217
if (processorType != null) {
218218
exception.addHeader("processor_type", processorType);

server/src/main/java/org/elasticsearch/ingest/TrackingResultProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void execute(IngestDocument ingestDocument, BiConsumer<IngestDocument, Ex
5353
if (e instanceof ElasticsearchException) {
5454
ElasticsearchException elasticsearchException = (ElasticsearchException) e;
5555
//else do nothing, let the tracking processors throw the exception while recording the path up to the failure
56-
if (elasticsearchException.getCause().getCause() instanceof IllegalStateException) {
56+
if (elasticsearchException.getCause() instanceof IllegalStateException) {
5757
if (ignoreFailure) {
5858
processorResultList.add(new SimulateProcessorResult(pipelineProcessor.getTag(),
5959
new IngestDocument(ingestDocument), e));

server/src/test/java/org/elasticsearch/action/ingest/SimulateExecutionServiceTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ public void testExecuteItemWithFailure() throws Exception {
259259
assertThat(simulateDocumentBaseResult.getFailure(), instanceOf(RuntimeException.class));
260260
Exception exception = simulateDocumentBaseResult.getFailure();
261261
assertThat(exception, instanceOf(ElasticsearchException.class));
262-
assertThat(exception.getMessage(), equalTo("java.lang.IllegalArgumentException: java.lang.RuntimeException: processor failed"));
262+
assertThat(exception.getMessage(), equalTo("java.lang.RuntimeException: processor failed"));
263263
}
264264

265265
public void testDropDocument() throws Exception {

server/src/test/java/org/elasticsearch/ingest/IngestServiceTests.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,8 @@ public String getType() {
625625
final SetOnce<Boolean> failure = new SetOnce<>();
626626
final IndexRequest indexRequest = new IndexRequest("_index").id("_id").source(emptyMap()).setPipeline(id);
627627
final BiConsumer<Integer, Exception> failureHandler = (slot, e) -> {
628-
assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
629-
assertThat(e.getCause().getCause(), instanceOf(IllegalStateException.class));
630-
assertThat(e.getCause().getCause().getMessage(), equalTo("error"));
628+
assertThat(e.getCause(), instanceOf(IllegalStateException.class));
629+
assertThat(e.getCause().getMessage(), equalTo("error"));
631630
failure.set(true);
632631
};
633632

@@ -916,7 +915,7 @@ public void testBulkRequestExecutionWithFailures() throws Exception {
916915
verify(requestItemErrorHandler, times(numIndexRequests)).accept(anyInt(), argThat(new ArgumentMatcher<Exception>() {
917916
@Override
918917
public boolean matches(final Object o) {
919-
return ((Exception)o).getCause().getCause().equals(error);
918+
return ((Exception)o).getCause().equals(error);
920919
}
921920
}));
922921
verify(completionHandler, times(1)).accept(Thread.currentThread(), null);

server/src/test/java/org/elasticsearch/ingest/TrackingResultProcessorTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,7 @@ public void testActualPipelineProcessorWithCycle() throws Exception {
457457
Exception[] holder = new Exception[1];
458458
trackingProcessor.execute(ingestDocument, (result, e) -> holder[0] = e);
459459
ElasticsearchException exception = (ElasticsearchException) holder[0];
460-
assertThat(exception.getCause(), instanceOf(IllegalArgumentException.class));
461-
assertThat(exception.getCause().getCause(), instanceOf(IllegalStateException.class));
460+
assertThat(exception.getCause(), instanceOf(IllegalStateException.class));
462461
assertThat(exception.getMessage(), containsString("Cycle detected for pipeline: pipeline1"));
463462
}
464463

0 commit comments

Comments
 (0)