From b888684ff696c20fe3ba9d042a4c3c1b4d018675 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Thu, 1 Sep 2011 19:25:04 +0300 Subject: [PATCH] negative from parameter yields undescriptive error message, closes #1293. --- .../org/elasticsearch/search/query/FromParseElement.java | 7 ++++++- .../org/elasticsearch/search/query/SizeParseElement.java | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/FromParseElement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/FromParseElement.java index 5559f890558..3324417f7c6 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/FromParseElement.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/FromParseElement.java @@ -21,6 +21,7 @@ package org.elasticsearch.search.query; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.search.SearchParseElement; +import org.elasticsearch.search.SearchParseException; import org.elasticsearch.search.internal.SearchContext; /** @@ -31,7 +32,11 @@ public class FromParseElement implements SearchParseElement { @Override public void parse(XContentParser parser, SearchContext context) throws Exception { XContentParser.Token token = parser.currentToken(); if (token.isValue()) { - context.from(parser.intValue()); + int from = parser.intValue(); + if (from < 0) { + throw new SearchParseException(context, "from is set to [" + from + "] and is expected to be higher or equal to 0"); + } + context.from(from); } } } diff --git a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/SizeParseElement.java b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/SizeParseElement.java index 2ec0ac26538..bd6433dc1cf 100644 --- a/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/SizeParseElement.java +++ b/modules/elasticsearch/src/main/java/org/elasticsearch/search/query/SizeParseElement.java @@ -21,6 +21,7 @@ package org.elasticsearch.search.query; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.search.SearchParseElement; +import org.elasticsearch.search.SearchParseException; import org.elasticsearch.search.internal.SearchContext; /** @@ -31,7 +32,11 @@ public class SizeParseElement implements SearchParseElement { @Override public void parse(XContentParser parser, SearchContext context) throws Exception { XContentParser.Token token = parser.currentToken(); if (token.isValue()) { - context.size(parser.intValue()); + int size = parser.intValue(); + if (size < 0) { + throw new SearchParseException(context, "size is set to [" + size + "] and is expected to be higher or equal to 0"); + } + context.size(size); } } } \ No newline at end of file