Skip to content

Commit aad7ce0

Browse files
committed
More plugging in
1 parent 2d6466f commit aad7ce0

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,17 @@ public class AbortedException extends SpannerException {
3535
/** Private constructor. Use {@link SpannerExceptionFactory} to create instances. */
3636
AbortedException(
3737
DoNotConstructDirectly token, @Nullable String message, @Nullable Throwable cause) {
38-
this(token, message, cause, null);
38+
this(token, message, cause, null, null);
3939
}
4040

4141
/** Private constructor. Use {@link SpannerExceptionFactory} to create instances. */
4242
AbortedException(
4343
DoNotConstructDirectly token,
4444
@Nullable String message,
4545
@Nullable Throwable cause,
46-
@Nullable ApiException apiException) {
47-
super(token, ErrorCode.ABORTED, IS_RETRYABLE, message, cause, apiException);
46+
@Nullable ApiException apiException,
47+
@Nullable XGoogSpannerRequestId reqId) {
48+
super(token, ErrorCode.ABORTED, IS_RETRYABLE, message, cause, apiException, reqId);
4849
}
4950

5051
/**

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

+24-8
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,22 @@ public static SpannerException newSpannerException(ErrorCode code, @Nullable Str
6262
}
6363

6464
public static SpannerException newSpannerException(
65-
ErrorCode code, @Nullable String message, @Nullable XGoogSpannerRequestId reqId) {
65+
ErrorCode code,
66+
@Nullable String message,
67+
@Nullable Throwable cause,
68+
@Nullable XGoogSpannerRequestId reqId) {
6669
return newSpannerExceptionPreformatted(
67-
code, formatMessage(code, message), (Throwable) (null), (ApiException) (null), reqId);
70+
code, formatMessage(code, message), cause, (ApiException) (null), reqId);
71+
}
72+
73+
public static SpannerException newSpannerException(
74+
ErrorCode code, @Nullable String message, @Nullable XGoogSpannerRequestId reqId) {
75+
return newSpannerException(code, message, (Throwable) (null), reqId);
6876
}
6977

7078
public static SpannerException newSpannerException(
7179
ErrorCode code, @Nullable String message, @Nullable Throwable cause) {
72-
return newSpannerExceptionPreformatted(code, formatMessage(code, message), cause, null, null);
80+
return newSpannerException(code, message, cause, null);
7381
}
7482

7583
public static SpannerException propagateInterrupt(InterruptedException e) {
@@ -121,9 +129,8 @@ public static SpannerException newSpannerException(Throwable cause) {
121129
return newSpannerException(null, cause, null);
122130
}
123131

124-
public static SpannerException newSpannerException(
125-
Throwable cause, XGoogSpannerRequestId requestId) {
126-
return newSpannerException(null, cause, requestId);
132+
public static SpannerException newSpannerException(Throwable cause, XGoogSpannerRequestId reqId) {
133+
return newSpannerException(null, cause, reqId);
127134
}
128135

129136
public static SpannerBatchUpdateException newSpannerBatchUpdateException(
@@ -185,6 +192,10 @@ public static SpannerBatchUpdateException newSpannerBatchUpdateException(
185192
cause);
186193
}
187194

195+
public static SpannerException newSpannerException(@Nullable Context context, Throwable cause) {
196+
return newSpannerException(context, cause, null);
197+
}
198+
188199
/**
189200
* Creates a new exception based on {@code cause}. If {@code cause} indicates cancellation, {@code
190201
* context} will be inspected to establish the type of cancellation.
@@ -230,6 +241,11 @@ static SpannerException newRetryOnDifferentGrpcChannelException(
230241
return new RetryOnDifferentGrpcChannelException(message, channel, cause);
231242
}
232243

244+
static SpannerException newSpannerExceptionForCancellation(
245+
@Nullable Context context, @Nullable Throwable cause) {
246+
return newSpannerExceptionForCancellation(context, cause, null);
247+
}
248+
233249
static SpannerException newSpannerExceptionForCancellation(
234250
@Nullable Context context, @Nullable Throwable cause, @Nullable XGoogSpannerRequestId reqId) {
235251
if (context != null && context.isCancelled()) {
@@ -247,7 +263,7 @@ static SpannerException newSpannerExceptionForCancellation(
247263
}
248264
}
249265
return newSpannerException(
250-
ErrorCode.CANCELLED, cause == null ? "Cancelled" : cause.getMessage(), cause);
266+
ErrorCode.CANCELLED, cause == null ? "Cancelled" : cause.getMessage(), cause, reqId);
251267
}
252268

253269
private static String formatMessage(ErrorCode code, @Nullable String message) {
@@ -325,7 +341,7 @@ static SpannerException newSpannerExceptionPreformatted(
325341
DoNotConstructDirectly token = DoNotConstructDirectly.ALLOWED;
326342
switch (code) {
327343
case ABORTED:
328-
return new AbortedException(token, message, cause, apiException);
344+
return new AbortedException(token, message, cause, apiException, reqId);
329345
case RESOURCE_EXHAUSTED:
330346
ErrorInfo info = extractErrorInfo(cause);
331347
if (info != null

0 commit comments

Comments
 (0)