Skip to content

Commit 0302f6e

Browse files
committed
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 896a4cc commit 0302f6e

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
@@ -668,8 +668,8 @@ teardown:
668668
}
669669
- length: { docs: 1 }
670670
- length: { docs.0.processor_results: 1 }
671-
- match: { docs.0.processor_results.0.error.reason: "java.lang.IllegalArgumentException: java.lang.IllegalStateException: Cycle detected for pipeline: outer" }
672-
- match: { docs.0.processor_results.0.error.caused_by.caused_by.reason: "Cycle detected for pipeline: outer" }
671+
- match: { docs.0.processor_results.0.error.reason: "java.lang.IllegalStateException: Cycle detected for pipeline: outer" }
672+
- match: { docs.0.processor_results.0.error.caused_by.reason: "Cycle detected for pipeline: outer" }
673673

674674
---
675675
"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
@@ -260,7 +260,7 @@ public void testExecuteItemWithFailure() throws Exception {
260260
assertThat(simulateDocumentBaseResult.getFailure(), instanceOf(RuntimeException.class));
261261
Exception exception = simulateDocumentBaseResult.getFailure();
262262
assertThat(exception, instanceOf(ElasticsearchException.class));
263-
assertThat(exception.getMessage(), equalTo("java.lang.IllegalArgumentException: java.lang.RuntimeException: processor failed"));
263+
assertThat(exception.getMessage(), equalTo("java.lang.RuntimeException: processor failed"));
264264
}
265265

266266
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
@@ -644,9 +644,8 @@ public String getType() {
644644
final SetOnce<Boolean> failure = new SetOnce<>();
645645
final IndexRequest indexRequest = new IndexRequest("_index", "_type", "_id").source(emptyMap()).setPipeline(id);
646646
final BiConsumer<Integer, Exception> failureHandler = (slot, e) -> {
647-
assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
648-
assertThat(e.getCause().getCause(), instanceOf(IllegalStateException.class));
649-
assertThat(e.getCause().getCause().getMessage(), equalTo("error"));
647+
assertThat(e.getCause(), instanceOf(IllegalStateException.class));
648+
assertThat(e.getCause().getMessage(), equalTo("error"));
650649
failure.set(true);
651650
};
652651

@@ -936,7 +935,7 @@ public void testBulkRequestExecutionWithFailures() throws Exception {
936935
verify(requestItemErrorHandler, times(numIndexRequests)).accept(anyInt(), argThat(new ArgumentMatcher<Exception>() {
937936
@Override
938937
public boolean matches(final Object o) {
939-
return ((Exception)o).getCause().getCause().equals(error);
938+
return ((Exception)o).getCause().equals(error);
940939
}
941940
}));
942941
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)