summaryrefslogtreecommitdiff
path: root/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java
diff options
context:
space:
mode:
authorSimon Willnauer <simonw@apache.org>2015-07-03 12:13:56 +0200
committerSimon Willnauer <simonw@apache.org>2015-07-03 13:51:11 +0200
commitac32f3d31083040f9e604cbad127ff8fbc7e0763 (patch)
treeecf8168bd9bd1d49421133d03477f3c5fe14c9f8 /core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java
parent275fdcc08dad1f193e2d0305ed79ebaff7cec0bc (diff)
Don't special-case on ElasticsearchWrapperException in toXContent
the specialization can cause stack overflows if an exception is a ElasticsearchWrapperException as well as a ElasticsearchException. This commit just relies on the unwrap logic now to find the cause and only renders if we the rendering exception is the cause otherwise forwards to the generic exception rendering. Closes #11994
Diffstat (limited to 'core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java')
-rw-r--r--core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java14
1 files changed, 14 insertions, 0 deletions
diff --git a/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java b/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java
index 34bc1178b0..581868ff39 100644
--- a/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java
+++ b/core/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java
@@ -32,14 +32,17 @@ import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
+import org.elasticsearch.common.xcontent.XContentLocation;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexException;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.query.TestQueryParsingException;
import org.elasticsearch.indices.IndexMissingException;
import org.elasticsearch.rest.RestStatus;
+import org.elasticsearch.search.SearchParseException;
import org.elasticsearch.search.SearchShardTarget;
import org.elasticsearch.test.ElasticsearchTestCase;
+import org.elasticsearch.test.TestSearchContext;
import org.elasticsearch.test.VersionUtils;
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
import org.elasticsearch.transport.RemoteTransportException;
@@ -178,6 +181,16 @@ public class ElasticsearchExceptionTests extends ElasticsearchTestCase {
public void testToXContent() throws IOException {
{
+ ElasticsearchException ex = new SearchParseException(new TestSearchContext(), "foo", new XContentLocation(1,0));
+ XContentBuilder builder = XContentFactory.jsonBuilder();
+ builder.startObject();
+ ex.toXContent(builder, ToXContent.EMPTY_PARAMS);
+ builder.endObject();
+
+ String expected = "{\"type\":\"search_parse_exception\",\"reason\":\"foo\",\"line\":1,\"col\":0}";
+ assertEquals(expected, builder.string());
+ }
+ {
ElasticsearchException ex = new ElasticsearchException("foo", new ElasticsearchException("bar", new IllegalArgumentException("index is closed", new RuntimeException("foobar"))));
XContentBuilder builder = XContentFactory.jsonBuilder();
builder.startObject();
@@ -226,6 +239,7 @@ public class ElasticsearchExceptionTests extends ElasticsearchTestCase {
ex.toXContent(otherBuilder, ToXContent.EMPTY_PARAMS);
otherBuilder.endObject();
assertEquals(otherBuilder.string(), builder.string());
+ assertEquals("{\"type\":\"file_not_found_exception\",\"reason\":\"foo not found\"}", builder.string());
}
}