You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a TransactionEventHandler decides to thrown an exception in beforeCommit(), the transaction is correctly rolled back. However, the exception message and the stack trace depend on whether there has been an attempt to create a label in the tx or not.
In cases where the attempt has been made, the whole exception looks like the database is broken, rather than revealing the real cause of the rollback. Also, there's a Neo4j NPE in the stack trace, which looks like a bug.
@Test
public void shouldProduceClearMessageAndTraceForTxFailure() throws InterruptedException {
final GraphDatabaseService database = new TestGraphDatabaseFactory().newImpermanentDatabase();
database.registerTransactionEventHandler(new TransactionEventHandler.Adapter<Object>() {
@Override
public Object beforeCommit(TransactionData data) throws Exception {
throw new RuntimeException("I'd like this tx to be rolled back!");
}
});
try (Transaction tx = database.beginTx()) {
database.createNode();
tx.success();
} catch (Exception e) {
assertEquals("Unable to commit transaction", e.getMessage());
//from the following stacktrace, I can clearly see what happened
e.printStackTrace();
}
try (Transaction tx = database.beginTx()) {
database.createNode(DynamicLabel.label("test"));
tx.success();
} catch (Exception e) {
//this is inconsistent with the above
assertEquals("Unable to resume or suspend running transaction", e.getMessage());
//this stacktrace doesn't give me any idea what happened and looks like something's wrong with the DB:
e.printStackTrace();
}
}
The text was updated successfully, but these errors were encountered:
I'm trying this on 3.1 and both exceptions look identical:
org.neo4j.graphdb.TransactionFailureException: Transaction was marked as successful, but unable to commit transaction so rolled back.
at org.neo4j.kernel.impl.coreapi.TopLevelTransaction.close(TopLevelTransaction.java:101)
...<test stack left out for brevity>...
Caused by: org.neo4j.kernel.api.exceptions.TransactionFailureException:
at org.neo4j.kernel.impl.api.KernelTransactionImplementation.commit(KernelTransactionImplementation.java:553)
at org.neo4j.kernel.impl.api.KernelTransactionImplementation.closeTransaction(KernelTransactionImplementation.java:484)
at org.neo4j.kernel.api.KernelTransaction.close(KernelTransaction.java:135)
at org.neo4j.kernel.impl.coreapi.TopLevelTransaction.close(TopLevelTransaction.java:79)
... 24 more
Caused by: org.neo4j.kernel.api.exceptions.TransactionHookException: Transaction handler failed.
at org.neo4j.kernel.impl.api.TransactionHooks$TransactionHooksState.add(TransactionHooks.java:102)
at org.neo4j.kernel.impl.api.TransactionHooks.beforeCommit(TransactionHooks.java:61)
at org.neo4j.kernel.impl.api.KernelTransactionImplementation.commit(KernelTransactionImplementation.java:549)
... 27 more
Caused by: java.lang.RuntimeException: I'd like this tx to be rolled back!
at TestYo$1.beforeCommit(TestYo.java:21)
at org.neo4j.kernel.internal.TransactionEventHandlers.beforeCommit(TransactionEventHandlers.java:127)
at org.neo4j.kernel.internal.TransactionEventHandlers.beforeCommit(TransactionEventHandlers.java:1)
... 29 more
When a TransactionEventHandler decides to thrown an exception in beforeCommit(), the transaction is correctly rolled back. However, the exception message and the stack trace depend on whether there has been an attempt to create a label in the tx or not.
In cases where the attempt has been made, the whole exception looks like the database is broken, rather than revealing the real cause of the rollback. Also, there's a Neo4j NPE in the stack trace, which looks like a bug.
The text was updated successfully, but these errors were encountered: