Skip to content

Commit

Permalink
fix: Stop catching throwable, use unchecked()
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Roberts <ryan@blockchaintp.com>
  • Loading branch information
ryan-s-roberts committed Jul 29, 2021
1 parent 36de47a commit ed773d1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ protected Store<K, V> getStore() {

final <T> T decorateGet(final CheckedFunction0<T> f) throws StoreReadException {
try {
return getRetry.executeCheckedSupplier(f);
} catch (StoreReadException e) {
throw e;
} catch (Throwable e) {
return getRetry.executeSupplier(f.unchecked());
} catch (RuntimeException e) {
throw new StoreReadException(e);
} catch (Exception e) {
if (e instanceof StoreReadException) {
throw e;
}
throw new StoreReadException(e);
}
}
Expand All @@ -105,14 +108,17 @@ public final Map<Key<K>, Value<V>> get(final List<Key<K>> listOfKeys) throws Sto

final void decoratePut(final CheckedRunnable f) throws StoreWriteException {
try {
putRetry.executeCheckedSupplier(() -> {
putRetry.executeSupplier(() -> {
/// We only have a checked Supplier<>, so return a null
f.run();
f.unchecked().run();
return null;
});
} catch (StoreWriteException e) {
throw e;
} catch (Throwable e) {
} catch (RuntimeException e) {
throw new StoreWriteException(e);
} catch (Exception e) {
if (e instanceof StoreReadException) {
throw e;
}
throw new StoreWriteException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import kr.pe.kwonnam.slf4jlambda.LambdaLogger;
import kr.pe.kwonnam.slf4jlambda.LambdaLoggerFactory;
import software.amazon.awssdk.core.exception.SdkException;
import software.amazon.awssdk.services.qldb.QldbClient;
import software.amazon.awssdk.services.qldb.model.CreateLedgerRequest;
import software.amazon.awssdk.services.qldb.model.DeleteLedgerRequest;
Expand Down Expand Up @@ -55,8 +56,7 @@ private boolean ledgerState(final LedgerState state) {
LOG.debug("Check ledger state, currently {}", current::get);

return current.get().equals(state);
} catch (Throwable e) {
// TODO this one is bad, we should not catch all exceptions
} catch (SdkException e) {
return current.get() == null && state.equals(LedgerState.DELETED);
}
}
Expand Down

0 comments on commit ed773d1

Please sign in to comment.