Skip to content

Commit

Permalink
Guess root cause support unwrap (#50525)
Browse files Browse the repository at this point in the history
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 #50417
  • Loading branch information
henningandersen committed Jan 8, 2020
1 parent cf933b1 commit 3c2771a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ teardown:
id: 1
pipeline: "outer"
body: {}
- match: { error.root_cause.0.type: "ingest_processor_exception" }
- match: { error.root_cause.0.reason: "java.lang.IllegalStateException: Cycle detected for pipeline: outer" }
- match: { error.root_cause.0.type: "illegal_state_exception" }
- match: { error.root_cause.0.reason: "Cycle detected for pipeline: outer" }

---
"Test Pipeline Processor with templating":
Expand Down Expand Up @@ -200,5 +200,5 @@ teardown:
{
"org": "legal"
}
- match: { error.root_cause.0.type: "ingest_processor_exception" }
- match: { error.root_cause.0.reason: "java.lang.IllegalStateException: Pipeline processor configured for non-existent pipeline [legal-department]" }
- match: { error.root_cause.0.type: "illegal_state_exception" }
- match: { error.root_cause.0.reason: "Pipeline processor configured for non-existent pipeline [legal-department]" }
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@
source: "ctx._source.ctx = ctx"
params: { bar: 'xxx' }

- match: { error.root_cause.0.type: "remote_transport_exception" }
- match: { error.root_cause.0.type: "illegal_argument_exception" }
- match: { error.type: "illegal_argument_exception" }
- match: { error.reason: "Iterable object is self-referencing itself" }
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ public static ElasticsearchException[] guessRootCauses(Throwable t) {
}
}
}
return new ElasticsearchException[]{new ElasticsearchException(t.getMessage(), t) {
return new ElasticsearchException[]{new ElasticsearchException(ex.getMessage(), ex) {
@Override
protected String getExceptionName() {
return getExceptionName(getCause());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,16 @@ public void testGuessRootCause() {
assertEquals("illegal_argument_exception", foobars[0].getExceptionName());
}

{
final ElasticsearchException[] foobars = ElasticsearchException.guessRootCauses(
new RemoteTransportException("abc", new IllegalArgumentException("foobar")));
assertEquals(foobars.length, 1);
assertThat(foobars[0], instanceOf(ElasticsearchException.class));
assertEquals("foobar", foobars[0].getMessage());
assertEquals(IllegalArgumentException.class, foobars[0].getCause().getClass());
assertEquals("illegal_argument_exception", foobars[0].getExceptionName());
}

{
XContentParseException inner = new XContentParseException(null, "inner");
XContentParseException outer = new XContentParseException(null, "outer", inner);
Expand Down

0 comments on commit 3c2771a

Please sign in to comment.