Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java driver promises should use checked exceptions where possible #688

Open
flyingsilverfin opened this issue Sep 26, 2024 · 0 comments
Open

Comments

@flyingsilverfin
Copy link
Member

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 awaited, 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant