From 60a6e4d4794a902b84eff8127baa6efa0b6ad14d Mon Sep 17 00:00:00 2001 From: Henning Andersen Date: Mon, 30 Dec 2019 16:04:05 +0100 Subject: [PATCH 1/2] 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 #50417 --- .../java/org/elasticsearch/ElasticsearchException.java | 2 +- .../org/elasticsearch/ElasticsearchExceptionTests.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/ElasticsearchException.java b/server/src/main/java/org/elasticsearch/ElasticsearchException.java index abaceff4f4e73..f588823f699b3 100644 --- a/server/src/main/java/org/elasticsearch/ElasticsearchException.java +++ b/server/src/main/java/org/elasticsearch/ElasticsearchException.java @@ -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()); diff --git a/server/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java b/server/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java index 9ed826de87cdd..570598831f944 100644 --- a/server/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java +++ b/server/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java @@ -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); From 2d0eb71be5f1828e6d52491ec8932fe3507a39b8 Mon Sep 17 00:00:00 2001 From: Henning Andersen Date: Wed, 1 Jan 2020 17:07:05 +0100 Subject: [PATCH 2/2] Fix tests A few rest tests mistakenly used a wrapper exception as the expected root cause. --- .../rest-api-spec/test/ingest/210_pipeline_processor.yml | 8 ++++---- .../resources/rest-api-spec/test/painless/15_update.yml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/210_pipeline_processor.yml b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/210_pipeline_processor.yml index 76dbc180fa0e5..a012536c53bb4 100644 --- a/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/210_pipeline_processor.yml +++ b/modules/ingest-common/src/test/resources/rest-api-spec/test/ingest/210_pipeline_processor.yml @@ -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": @@ -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]" } diff --git a/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/15_update.yml b/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/15_update.yml index 15e93bf621c7e..cb118ed9d562f 100644 --- a/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/15_update.yml +++ b/modules/lang-painless/src/test/resources/rest-api-spec/test/painless/15_update.yml @@ -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" }