Remove circular dependency between syncbase and exception packages.
Remove dependency of Exceptions class on Id class. This makes for a
cleaner design, but also makes it easier to build this code with
Blaze.
Also added Javadoc for public Exceptions methods.
Change-Id: I1451f13c178ee3614363c6c832a2f5ca9211388f
diff --git a/syncbase/src/main/java/io/v/syncbase/Collection.java b/syncbase/src/main/java/io/v/syncbase/Collection.java
index 8742522..a6251e5 100644
--- a/syncbase/src/main/java/io/v/syncbase/Collection.java
+++ b/syncbase/src/main/java/io/v/syncbase/Collection.java
@@ -75,9 +75,9 @@
if (vError.id.equals(VError.NO_EXIST)) {
return null;
}
- chainThrow("getting value from collection", mId, vError);
+ chainThrow("getting value from collection", mId.getName(), vError);
} catch (VException e) {
- chainThrow("decoding value retrieved from collection", mId, e);
+ chainThrow("decoding value retrieved from collection", mId.getName(), e);
}
throw new AssertionError("never happens");
}
@@ -91,7 +91,7 @@
return mCoreCollection.row(key).exists();
} catch (VError e) {
- chainThrow("checking if value exists in collection", mId, e);
+ chainThrow("checking if value exists in collection", mId.getName(), e);
throw new AssertionError("never happens");
}
}
@@ -105,9 +105,9 @@
mCoreCollection.put(key, VomUtil.encode(value, value.getClass()));
} catch (VError e) {
- chainThrow("putting value into collection", mId, e);
+ chainThrow("putting value into collection", mId.getName(), e);
} catch (VException e) {
- chainThrow("putting value into collection", mId, e);
+ chainThrow("putting value into collection", mId.getName(), e);
}
}
@@ -120,7 +120,7 @@
mCoreCollection.delete(key);
} catch (VError e) {
- chainThrow("deleting collection", mId, e);
+ chainThrow("deleting collection", mId.getName(), e);
}
}
@@ -134,7 +134,7 @@
return new AccessList(mCoreCollection.getPermissions());
} catch (VError e) {
- chainThrow("getting access list of collection", mId, e);
+ chainThrow("getting access list of collection", mId.getName(), e);
throw new AssertionError("never happens");
}
}
@@ -155,7 +155,7 @@
coreCollection.getPermissions(), delta);
coreCollection.setPermissions(newPermissions);
} catch (VError vError) {
- chainThrow("setting permissions in collection", id, vError);
+ chainThrow("setting permissions in collection", id.getName(), vError);
}
}
};
diff --git a/syncbase/src/main/java/io/v/syncbase/Database.java b/syncbase/src/main/java/io/v/syncbase/Database.java
index 00c0858..724d866 100644
--- a/syncbase/src/main/java/io/v/syncbase/Database.java
+++ b/syncbase/src/main/java/io/v/syncbase/Database.java
@@ -144,7 +144,7 @@
return syncgroups.iterator();
} catch (VError e) {
- chainThrow("getting syncgroups of database", mCoreDatabase.id(), e);
+ chainThrow("getting syncgroups of database", mCoreDatabase.id().name, e);
throw new AssertionError("never happens");
}
}
@@ -338,7 +338,7 @@
}, opts.toCore());
} catch (VError e) {
- chainThrow("running batch operation in database", mCoreDatabase.id(), e);
+ chainThrow("running batch operation in database", mCoreDatabase.id().name, e);
}
}
@@ -383,7 +383,7 @@
return new BatchDatabase(mCoreDatabase.beginBatch(opts.toCore()));
} catch (VError e) {
- chainThrow("creating batch in database", mCoreDatabase.id(), e);
+ chainThrow("creating batch in database", mCoreDatabase.id().name, e);
throw new AssertionError("never happens");
}
}
diff --git a/syncbase/src/main/java/io/v/syncbase/DatabaseHandle.java b/syncbase/src/main/java/io/v/syncbase/DatabaseHandle.java
index 90a8761..07c05f9 100644
--- a/syncbase/src/main/java/io/v/syncbase/DatabaseHandle.java
+++ b/syncbase/src/main/java/io/v/syncbase/DatabaseHandle.java
@@ -94,7 +94,7 @@
return collections.iterator();
} catch (VError e) {
- chainThrow("getting collections in database", mCoreDatabaseHandle.id(), e);
+ chainThrow("getting collections in database", mCoreDatabaseHandle.id().name, e);
throw new AssertionError("never happens");
}
}
diff --git a/syncbase/src/main/java/io/v/syncbase/Syncgroup.java b/syncbase/src/main/java/io/v/syncbase/Syncgroup.java
index ef41110..ec0415e 100644
--- a/syncbase/src/main/java/io/v/syncbase/Syncgroup.java
+++ b/syncbase/src/main/java/io/v/syncbase/Syncgroup.java
@@ -91,7 +91,7 @@
// return new AccessList(mCoreSyncgroup.getSpec().syncgroupSpec.permissions);
} catch (VError e) {
- chainThrow("getting access list of syncgroup", getId(), e);
+ chainThrow("getting access list of syncgroup", getId().getName(), e);
throw new AssertionError("never happens");
}
}
@@ -187,7 +187,7 @@
});
} catch (VError e) {
- chainThrow("updating access list of syncgroup", getId(), e);
+ chainThrow("updating access list of syncgroup", getId().getName(), e);
}
}
}
diff --git a/syncbase/src/main/java/io/v/syncbase/WatchChange.java b/syncbase/src/main/java/io/v/syncbase/WatchChange.java
index b8ab288..1d007e5 100644
--- a/syncbase/src/main/java/io/v/syncbase/WatchChange.java
+++ b/syncbase/src/main/java/io/v/syncbase/WatchChange.java
@@ -78,7 +78,8 @@
try {
return (T) VomUtil.decode(mValue, cls);
} catch (VException e) {
- chainThrow("getting value from a WatchChange of collection", mCollectionId, e);
+ chainThrow(
+ "getting value from a WatchChange of collection", mCollectionId.getName(), e);
throw new AssertionError("never happens");
}
}
diff --git a/syncbase/src/main/java/io/v/syncbase/exception/Exceptions.java b/syncbase/src/main/java/io/v/syncbase/exception/Exceptions.java
index c01821c..5c08a38 100644
--- a/syncbase/src/main/java/io/v/syncbase/exception/Exceptions.java
+++ b/syncbase/src/main/java/io/v/syncbase/exception/Exceptions.java
@@ -7,7 +7,6 @@
import java.util.NoSuchElementException;
import java.util.concurrent.CancellationException;
-import io.v.syncbase.Id;
import io.v.syncbase.core.VError;
import io.v.v23.verror.VException;
import io.v.v23.verror.VException.ActionCode;
@@ -119,28 +118,54 @@
chainThrow("while " + javaMessage + " got error " + goMessage, v23ErrorId, action, cause);
}
+ /**
+ * Throw an exception that wraps a low-level exception.
+ *
+ * @param javaMessage gives context from where the low-level exception was caught
+ * @param cause the low-level exception, possibly originating in native code
+ * @throws SyncbaseException always
+ */
public static void chainThrow(String javaMessage, VError cause) throws SyncbaseException {
ActionCode action = fromValue((int) cause.actionCode);
chainThrow(javaMessage, cause.message, cause.id, action, cause);
}
+ /**
+ * Throw an exception that wraps a low-level exception.
+ *
+ * @param javaMessage gives context from where the low-level exception was caught
+ * @param cause the low-level exception, possibly originating in native code
+ * @throws SyncbaseException always
+ */
public static void chainThrow(String javaMessage, VException cause) throws SyncbaseException {
chainThrow(javaMessage, cause.getMessage(), cause.getID(), cause.getAction(),
cause);
}
- public static void chainThrow(String doing, Id where, VError cause) throws SyncbaseException {
- chainThrow(doing + " " + where.getName(), cause);
+ /**
+ * Throw an exception that wraps a low-level exception.
+ *
+ * @param doing what the high-level code was doing when the exception was caught
+ * @param name a Vanadoum name, i.e the name field of an Id object
+ * @param cause the low-level exception, possibly originating in native code
+ * @throws SyncbaseException always
+ */
+ public static void chainThrow(String doing, String name, VError cause) throws
+ SyncbaseException {
+ chainThrow(doing + " " + name, cause);
}
- public static void chainThrow(String doing, Id where, VException cause) throws
+ /**
+ * Throw an exception that wraps a low-level exception.
+ *
+ * @param doing what the high-level code was doing when the exception was caught
+ * @param name a Vanadoum name, i.e the name field of an Id object
+ * @param cause the low-level exception, possibly originating in native code
+ * @throws SyncbaseException always
+ */
+ public static void chainThrow(String doing, String name, VException cause) throws
SyncbaseException {
- chainThrow(doing + " " + where.getName(), cause);
- }
-
- public static void chainThrow(String doing, io.v.syncbase.core.Id where, VError cause) throws
- SyncbaseException {
- chainThrow(doing + " " + where.name, cause);
+ chainThrow(doing + " " + name, cause);
}
private static <T extends Exception> T withCause(T e, Exception cause) {