Propagate Rust errors through as Java exceptions
- Error handling from Rust to Java is now greatly improved by properly utilizing Java checked and unchecked exceptions.
- We define a set of Java checked exception classes:
-
OnionmasqException
: a general checked exception for all Rust errors with no more specific subclass -
ArtiException
: for Arti errors with no more specific subclass -
ArtiStateException
: when Arti failed to initialise due to a problem with its state or cache directories (which could be cleared from Java before retrying). -
TorAccessException
: when Arti failed to connect to the Tor network, likely due to local network conditions (which might want to be presented as some form of 'network down or censored' error?)
-
- Errors that cannot reasonably be expected to be handled in Rust, like
panics, are now properly represented as unchecked exceptions in Java:
-
RustPanicException
now represents panics, instead of the previously overly generic and wrongjava.lang.Exception
-
JniMisuseException
is raised for all JNI-related troubles.
-
- We might add more of these as needed to cover different failure cases;
the translation is implemented by a new
errors
module inonionmasq-mobile
.- We resist the temptation to define a custom error
enum
and just loop through the error chain at runtime. - This lets us keep the convenience and feature set of
anyhow
(no having to custom define enum variants, easy context addition, etc). - We can adjust the translation logic as needed in future easily, too!
- We resist the temptation to define a custom error
cc @cyberta -- would you mind taking a look at the Java side of things? thanks!