mirror of
https://github.com/google/nomulus
synced 2026-09-06 08:07:03 +00:00
Don't wrap exceptions thrown inside Cloud SQL transactions (#338)
* Don't wrap exceptions thrown inside Cloud SQL transactions There's no reason to wrap them in PersistenceException, and it makes dealing with thrown exceptions harder as seen in the diffs on test classes in this commit.
This commit is contained in:
@@ -41,6 +41,7 @@ public final class RegistryLockDao {
|
||||
Long.class)
|
||||
.setParameter("verificationCode", verificationCode)
|
||||
.getSingleResult();
|
||||
// TODO(gbrodman): Don't throw NPE here. Maybe NoResultException fits better?
|
||||
checkNotNull(revisionId, "No registry lock with this code");
|
||||
return em.find(RegistryLock.class, revisionId);
|
||||
});
|
||||
|
||||
@@ -79,17 +79,14 @@ public class JpaTransactionManagerImpl implements JpaTransactionManager {
|
||||
T result = work.run();
|
||||
txn.commit();
|
||||
return result;
|
||||
} catch (Throwable transactionException) {
|
||||
String rollbackMessage;
|
||||
} catch (RuntimeException e) {
|
||||
try {
|
||||
txn.rollback();
|
||||
rollbackMessage = "transaction rolled back";
|
||||
logger.atWarning().log("Error during transaction; transaction rolled back");
|
||||
} catch (Throwable rollbackException) {
|
||||
logger.atSevere().withCause(rollbackException).log("Rollback failed, suppressing error");
|
||||
rollbackMessage = "transaction rollback failed";
|
||||
logger.atSevere().withCause(rollbackException).log("Rollback failed; suppressing error");
|
||||
}
|
||||
throw new PersistenceException(
|
||||
"Error during transaction, " + rollbackMessage, transactionException);
|
||||
throw e;
|
||||
} finally {
|
||||
txnInfo.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user