Description
Problem to Solve
In TypeDB 3.0 drivers, the Java transaction.query()
API returns a Promise<QueryAnswer>
. However, we know that sometimes, there can be parsing errors, compile errors, etc. that arise before iterating the answers.
In Rust, this same function has the following signature: async Transaction::query(...) -> Result<QueryAnswer>
, which indicates that once the .query()
is await
ed, the result must be inspected. In Java, the way to enforce this is to use a Checked exception:
var promise = transaction.query(...);
promise.resolve(); // should require the user to wrap in a try..catch
Proposed Solution
We should introduce two types of Promise
in Java - CheckedPromise
, and Promise
. When we know the promise-based operation can fail, we should enforce the user catches it by returning a CheckedPromise
. Otherwise, it should be an Promise
that cannot will not fail (or only throw Runtime exceptions).