Skip to content

Commit 60a6e4d

Browse files
Guess root cause support unwrap
ElasticsearchException.guessRootCauses would return wrapper exception if inner exception was not an ElasticsearchException. Fixed to never return wrapper exceptions. Relates elastic#50417
1 parent 66959be commit 60a6e4d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

+1-1
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

+10
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)