refactor: throw better error message when creating a bad entity id from a string
@@ -47,11 +47,18 @@ class EntityId {
static <R> R fromString(String id, WithIdNums<R> withIdNums) {
var nums = Splitter.on('.').split(id).iterator();
+ R newId;
+
+ try {
var shard = Long.parseLong(nums.next());
var realm = Long.parseLong(nums.next());
var num = Long.parseLong(nums.next());
+ newId = withIdNums.apply(shard, realm, num);
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Invalid Id format, should be in format {shardNum}.{realmNum}.{idNum}", e);
+ }
- return withIdNums.apply(shard, realm, num);
+ return newId;
}
private static void checkAddressLen(byte[] address) {
