@@ -320,7 +320,10 @@ public CompletionStage<Void> terminateAsync() {
320320
321321 @ Override
322322 public <T > T execute (Function <Throwable , T > causeOfTerminationConsumer ) {
323- return executeWithLock (lock , () -> causeOfTerminationConsumer .apply (causeOfTermination ));
323+ return executeWithLock (lock , () -> {
324+ var throwable = causeOfTermination == null ? null : failedTxException (causeOfTermination );
325+ return causeOfTerminationConsumer .apply (throwable );
326+ });
324327 }
325328
326329 private void ensureCanRunQueries () {
@@ -347,15 +350,7 @@ private void ensureCanRunQueries() {
347350 if (causeOfTermination instanceof TransactionTerminatedException transactionTerminatedException ) {
348351 throw transactionTerminatedException ;
349352 } else {
350- var message =
351- "Cannot run more queries in this transaction, it has either experienced an fatal error or was explicitly terminated" ;
352- throw new TransactionTerminatedException (
353- GqlStatusError .UNKNOWN .getStatus (),
354- GqlStatusError .UNKNOWN .getStatusDescription (message ),
355- "N/A" ,
356- message ,
357- GqlStatusError .DIAGNOSTIC_RECORD ,
358- causeOfTermination );
353+ throw failedTxException (causeOfTermination );
359354 }
360355 } else if (commitFuture != null ) {
361356 var message = "Cannot run more queries in this transaction, it is being committed" ;
@@ -578,6 +573,18 @@ private CompletionStage<Void> closeAsync(boolean commit, boolean completeWithNul
578573 return stage ;
579574 }
580575
576+ private static TransactionTerminatedException failedTxException (Throwable cause ) {
577+ var message =
578+ "Cannot run more queries in this transaction, it has either experienced a fatal error or was explicitly terminated" ;
579+ return new TransactionTerminatedException (
580+ GqlStatusError .UNKNOWN .getStatus (),
581+ GqlStatusError .UNKNOWN .getStatusDescription (message ),
582+ "N/A" ,
583+ message ,
584+ GqlStatusError .DIAGNOSTIC_RECORD ,
585+ cause );
586+ }
587+
581588 private static class BeginResponseHandler implements DriverResponseHandler {
582589 final CompletableFuture <UnmanagedTransaction > summaryFuture = new CompletableFuture <>();
583590 private final ApiTelemetryWork apiTelemetryWork ;
0 commit comments