Skip to content

Commit cd58c99

Browse files
committed
chore(spanner): update exception block
1 parent 3778a5b commit cd58c99

File tree

7 files changed

+20
-31
lines changed

7 files changed

+20
-31
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/DelayedAsyncRunner.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.google.api.core.ApiFutures;
2121
import com.google.cloud.Timestamp;
2222
import com.google.common.util.concurrent.MoreExecutors;
23+
import java.util.concurrent.ExecutionException;
2324
import java.util.concurrent.Executor;
2425

2526
/**
@@ -43,7 +44,10 @@ ApiFuture<AsyncRunner> getAsyncRunner() {
4344
if (exception instanceof InterruptedException) {
4445
throw SpannerExceptionFactory.propagateInterrupt((InterruptedException) exception);
4546
}
46-
throw SpannerExceptionFactory.asSpannerException(exception.getCause());
47+
if (exception instanceof ExecutionException) {
48+
throw SpannerExceptionFactory.causeAsRunTimeException((ExecutionException) exception);
49+
}
50+
throw exception;
4751
},
4852
MoreExecutors.directExecutor());
4953
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/DelayedAsyncTransactionManager.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ AsyncTransactionManager getAsyncTransactionManager() {
3939
try {
4040
return this.asyncTransactionManagerApiFuture.get();
4141
} catch (ExecutionException executionException) {
42-
// Propagate the underlying exception as a RuntimeException (SpannerException is also a
43-
// RuntimeException).
44-
if (executionException.getCause() instanceof RuntimeException) {
45-
throw (RuntimeException) executionException.getCause();
46-
}
47-
throw SpannerExceptionFactory.asSpannerException(executionException.getCause());
42+
throw SpannerExceptionFactory.causeAsRunTimeException(executionException);
4843
} catch (InterruptedException interruptedException) {
4944
throw SpannerExceptionFactory.propagateInterrupt(interruptedException);
5045
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/DelayedMultiplexedSessionTransaction.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,7 @@ private SessionReference getSessionReference() {
219219
try {
220220
return this.sessionFuture.get();
221221
} catch (ExecutionException executionException) {
222-
// Propagate the underlying exception as a RuntimeException (SpannerException is also a
223-
// RuntimeException).
224-
if (executionException.getCause() instanceof RuntimeException) {
225-
throw (RuntimeException) executionException.getCause();
226-
}
227-
throw SpannerExceptionFactory.asSpannerException(executionException.getCause());
222+
throw SpannerExceptionFactory.causeAsRunTimeException(executionException);
228223
} catch (InterruptedException interruptedException) {
229224
throw SpannerExceptionFactory.propagateInterrupt(interruptedException);
230225
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/DelayedReadContext.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,7 @@ T getReadContext() {
4444
try {
4545
return this.readContextFuture.get();
4646
} catch (ExecutionException executionException) {
47-
// Propagate the underlying exception as a RuntimeException (SpannerException is also a
48-
// RuntimeException).
49-
if (executionException.getCause() instanceof RuntimeException) {
50-
throw (RuntimeException) executionException.getCause();
51-
}
52-
throw SpannerExceptionFactory.asSpannerException(executionException.getCause());
47+
throw SpannerExceptionFactory.causeAsRunTimeException(executionException);
5348
} catch (InterruptedException interruptedException) {
5449
throw SpannerExceptionFactory.propagateInterrupt(interruptedException);
5550
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/DelayedTransactionManager.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ TransactionManager getTransactionManager() {
3838
try {
3939
return this.transactionManagerFuture.get();
4040
} catch (ExecutionException executionException) {
41-
// Propagate the underlying exception as a RuntimeException (SpannerException is also a
42-
// RuntimeException).
43-
if (executionException.getCause() instanceof RuntimeException) {
44-
throw (RuntimeException) executionException.getCause();
45-
}
46-
throw SpannerExceptionFactory.asSpannerException(executionException.getCause());
41+
throw SpannerExceptionFactory.causeAsRunTimeException(executionException);
4742
} catch (InterruptedException interruptedException) {
4843
throw SpannerExceptionFactory.propagateInterrupt(interruptedException);
4944
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/DelayedTransactionRunner.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ TransactionRunner getTransactionRunner() {
3838
try {
3939
return this.transactionRunnerFuture.get();
4040
} catch (ExecutionException executionException) {
41-
// Propagate the underlying exception as a RuntimeException (SpannerException is also a
42-
// RuntimeException).
43-
if (executionException.getCause() instanceof RuntimeException) {
44-
throw (RuntimeException) executionException.getCause();
45-
}
46-
throw SpannerExceptionFactory.asSpannerException(executionException.getCause());
41+
throw SpannerExceptionFactory.causeAsRunTimeException(executionException);
4742
} catch (InterruptedException interruptedException) {
4843
throw SpannerExceptionFactory.propagateInterrupt(interruptedException);
4944
}

google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerExceptionFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import io.grpc.StatusRuntimeException;
3232
import io.grpc.protobuf.ProtoUtils;
3333
import java.util.concurrent.CancellationException;
34+
import java.util.concurrent.ExecutionException;
3435
import java.util.concurrent.TimeoutException;
3536
import javax.annotation.Nullable;
3637

@@ -181,6 +182,15 @@ public static SpannerException newSpannerException(@Nullable Context context, Th
181182
return newSpannerException(ErrorCode.fromGrpcStatus(status), cause.getMessage(), cause);
182183
}
183184

185+
public static RuntimeException causeAsRunTimeException(ExecutionException executionException) {
186+
// Propagate the underlying exception as a RuntimeException (SpannerException is also a
187+
// RuntimeException).
188+
if (executionException.getCause() instanceof RuntimeException) {
189+
throw (RuntimeException) executionException.getCause();
190+
}
191+
throw asSpannerException(executionException.getCause());
192+
}
193+
184194
/**
185195
* Creates a new SpannerException that indicates that the RPC or transaction should be retried on
186196
* a different gRPC channel. This is an experimental feature that can be removed in the future.

0 commit comments

Comments
 (0)