Skip to content

Commit

Permalink
Feature no. 1, "nicer exception" has been implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Solitaire96 committed Mar 13, 2015
1 parent 99dcb3a commit 12aea17
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.elasticsearch.search.internal.ShardSearchTransportRequest;

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;

/**
Expand Down Expand Up @@ -94,23 +95,24 @@ public static ParsedScrollId parseScrollId(String scrollId) {
throw new ElasticsearchIllegalArgumentException("Failed to decode scrollId", e);
}
String[] elements = Strings.splitStringToArray(spare.get(), ';');
System.out.println(Arrays.toString(elements));
if (elements.length < 2) {
throw new ElasticsearchIllegalArgumentException("Malformed scrollId [" + scrollId + "]");
throw new ElasticsearchIllegalArgumentException("Malformed scrollId [" + scrollId + "], type and size parameters not provided");
}

int index = 0;
String type = elements[index++];
int contextSize = Integer.parseInt(elements[index++]);
if (elements.length < contextSize + 2) {
throw new ElasticsearchIllegalArgumentException("Malformed scrollId [" + scrollId + "]");
throw new ElasticsearchIllegalArgumentException("Malformed scrollId [" + scrollId + "], size is less than number of actual shards");
}

@SuppressWarnings({"unchecked"}) Tuple<String, Long>[] context = new Tuple[contextSize];
for (int i = 0; i < contextSize; i++) {
String element = elements[index++];
int sep = element.indexOf(':');
if (sep == -1) {
throw new ElasticsearchIllegalArgumentException("Malformed scrollId [" + scrollId + "]");
throw new ElasticsearchIllegalArgumentException("Malformed scrollId [" + scrollId + "], shard number is either missing or incorrectly separated from the ID");
}
context[i] = new Tuple<>(element.substring(sep + 1), Long.parseLong(element.substring(0, sep)));
}
Expand Down

0 comments on commit 12aea17

Please sign in to comment.