@@ -320,7 +320,10 @@ public CompletionStage<Void> terminateAsync() {
320
320
321
321
@ Override
322
322
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
+ });
324
327
}
325
328
326
329
private void ensureCanRunQueries () {
@@ -347,15 +350,7 @@ private void ensureCanRunQueries() {
347
350
if (causeOfTermination instanceof TransactionTerminatedException transactionTerminatedException ) {
348
351
throw transactionTerminatedException ;
349
352
} 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 );
359
354
}
360
355
} else if (commitFuture != null ) {
361
356
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
578
573
return stage ;
579
574
}
580
575
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
+
581
588
private static class BeginResponseHandler implements DriverResponseHandler {
582
589
final CompletableFuture <UnmanagedTransaction > summaryFuture = new CompletableFuture <>();
583
590
private final ApiTelemetryWork apiTelemetryWork ;
0 commit comments