Skip to content

Commit 5d25a0b

Browse files
henningandersenSivagurunathanV
authored andcommitted
Guess root cause support unwrap (elastic#50525)
ElasticsearchException.guessRootCauses would return wrapper exception if inner exception was not an ElasticsearchException. Fixed to never return wrapper exceptions. At least following APIs change root_cause.0.type as a result: _update with bad script _index with bad pipeline Relates elastic#50417
1 parent 01cff0d commit 5d25a0b

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ teardown:
106106
id: 1
107107
pipeline: "outer"
108108
body: {}
109-
- match: { error.root_cause.0.type: "ingest_processor_exception" }
110-
- match: { error.root_cause.0.reason: "java.lang.IllegalStateException: Cycle detected for pipeline: outer" }
109+
- match: { error.root_cause.0.type: "illegal_state_exception" }
110+
- match: { error.root_cause.0.reason: "Cycle detected for pipeline: outer" }
111111

112112
---
113113
"Test Pipeline Processor with templating":
@@ -200,5 +200,5 @@ teardown:
200200
{
201201
"org": "legal"
202202
}
203-
- match: { error.root_cause.0.type: "ingest_processor_exception" }
204-
- match: { error.root_cause.0.reason: "java.lang.IllegalStateException: Pipeline processor configured for non-existent pipeline [legal-department]" }
203+
- match: { error.root_cause.0.type: "illegal_state_exception" }
204+
- match: { error.root_cause.0.reason: "Pipeline processor configured for non-existent pipeline [legal-department]" }

modules/lang-painless/src/test/resources/rest-api-spec/test/painless/15_update.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,6 @@
120120
source: "ctx._source.ctx = ctx"
121121
params: { bar: 'xxx' }
122122

123-
- match: { error.root_cause.0.type: "remote_transport_exception" }
123+
- match: { error.root_cause.0.type: "illegal_argument_exception" }
124124
- match: { error.type: "illegal_argument_exception" }
125125
- match: { error.reason: "Iterable object is self-referencing itself" }

server/src/main/java/org/elasticsearch/ElasticsearchException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ public static ElasticsearchException[] guessRootCauses(Throwable t) {
641641
}
642642
}
643643
}
644-
return new ElasticsearchException[]{new ElasticsearchException(t.getMessage(), t) {
644+
return new ElasticsearchException[]{new ElasticsearchException(ex.getMessage(), ex) {
645645
@Override
646646
protected String getExceptionName() {
647647
return getExceptionName(getCause());

server/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ public void testGuessRootCause() {
163163
assertEquals("illegal_argument_exception", foobars[0].getExceptionName());
164164
}
165165

166+
{
167+
final ElasticsearchException[] foobars = ElasticsearchException.guessRootCauses(
168+
new RemoteTransportException("abc", new IllegalArgumentException("foobar")));
169+
assertEquals(foobars.length, 1);
170+
assertThat(foobars[0], instanceOf(ElasticsearchException.class));
171+
assertEquals("foobar", foobars[0].getMessage());
172+
assertEquals(IllegalArgumentException.class, foobars[0].getCause().getClass());
173+
assertEquals("illegal_argument_exception", foobars[0].getExceptionName());
174+
}
175+
166176
{
167177
XContentParseException inner = new XContentParseException(null, "inner");
168178
XContentParseException outer = new XContentParseException(null, "outer", inner);

0 commit comments

Comments
 (0)