From 744de1f6cbd36a2e1e98273b9d602802c8dcd89a Mon Sep 17 00:00:00 2001 From: Isabel Drost-Fromm Date: Mon, 14 Mar 2016 14:00:58 +0100 Subject: [PATCH] Throw ParsingExceptions instead of IllegalArgument ... keeps track of the position of the error. --- .../java/org/elasticsearch/search/sort/FieldSortBuilder.java | 3 ++- .../org/elasticsearch/search/sort/AbstractSortTestCase.java | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java index 4ead35fd96b..1157457afb9 100644 --- a/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java @@ -21,6 +21,7 @@ package org.elasticsearch.search.sort; import org.apache.lucene.util.BytesRef; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.lucene.BytesRefs; @@ -305,7 +306,7 @@ public class FieldSortBuilder extends SortBuilder implements S if (context.parseFieldMatcher().match(currentFieldName, NESTED_FILTER)) { nestedFilter = context.parseInnerQueryBuilder(); } else { - throw new IllegalArgumentException("Expected " + NESTED_FILTER.getPreferredName() + " element."); + throw new ParsingException(parser.getTokenLocation(), "Expected " + NESTED_FILTER.getPreferredName() + " element."); } } else if (token.isValue()) { if (context.parseFieldMatcher().match(currentFieldName, NESTED_PATH)) { diff --git a/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java b/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java index def78acf5af..6c5800c97cb 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java @@ -19,6 +19,7 @@ package org.elasticsearch.search.sort; +import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -85,6 +86,8 @@ public abstract class AbstractSortTestCase