solanaj
solanaj copied to clipboard
[v2] Use RpcResponse<T> instead of exception-driven development
Discuss:
For Version 2, I'd like to remove the required try-catch'ing of RpcException
. I've received feedback that it's a bad pattern to catch exceptions as a requirement. I believe changing the method signatures on RpcApi would break all clients, thus a major version (v2) would have these changes. I'm strongly against breaking clients, but v2 is needed. I could be wrong on any of these so please opine.
Example:
Current: (requires a try-catch block which is deal-breaking for some)
try {
long balance = client.getApi().getBalance(...);
} catch (RpcException ex) {
log.error(ex);
}
Future: (does not require exceptions)
RpcResponse<Long> response = client.getApi().getBalance();
if (response.isSuccessful()) {
// happy path
long balance = response.getValue();
} else {
// handle/log error gracefully
log.error("...");
}