Skip to content

Commit c102cb4

Browse files
authored
chore: add x-goog-request-id insertion into *Exception (#3813)
Allows users to examine and report the requestId in any thrown exceptions.
1 parent 8919c5e commit c102cb4

18 files changed

+156
-61
lines changed

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

Lines changed: 4 additions & 3 deletions
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/AdminRequestsPerMinuteExceededException.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ public class AdminRequestsPerMinuteExceededException extends SpannerException {
3232
/** Private constructor. Use {@link SpannerExceptionFactory} to create instances. */
3333
AdminRequestsPerMinuteExceededException(
3434
DoNotConstructDirectly token, @Nullable String message, @Nullable Throwable cause) {
35-
this(token, message, cause, null);
35+
this(token, message, cause, null, null);
3636
}
3737

3838
/** Private constructor. Use {@link SpannerExceptionFactory} to create instances. */
3939
AdminRequestsPerMinuteExceededException(
4040
DoNotConstructDirectly token,
4141
@Nullable String message,
4242
@Nullable Throwable cause,
43-
@Nullable ApiException apiException) {
44-
super(token, ErrorCode.RESOURCE_EXHAUSTED, true, message, cause, apiException);
43+
@Nullable ApiException apiException,
44+
@Nullable XGoogSpannerRequestId reqId) {
45+
super(token, ErrorCode.RESOURCE_EXHAUSTED, true, message, cause, apiException, reqId);
4546
}
4647
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class DatabaseNotFoundException extends ResourceNotFoundException {
3535
@Nullable String message,
3636
ResourceInfo resourceInfo,
3737
@Nullable Throwable cause) {
38-
this(token, message, resourceInfo, cause, null);
38+
this(token, message, resourceInfo, cause, null, null);
3939
}
4040

4141
/** Private constructor. Use {@link SpannerExceptionFactory} to create instances. */
@@ -44,7 +44,8 @@ public class DatabaseNotFoundException extends ResourceNotFoundException {
4444
@Nullable String message,
4545
ResourceInfo resourceInfo,
4646
@Nullable Throwable cause,
47-
@Nullable ApiException apiException) {
48-
super(token, message, resourceInfo, cause, apiException);
47+
@Nullable ApiException apiException,
48+
@Nullable XGoogSpannerRequestId reqId) {
49+
super(token, message, resourceInfo, cause, apiException, reqId);
4950
}
5051
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ public class InstanceNotFoundException extends ResourceNotFoundException {
3535
@Nullable String message,
3636
ResourceInfo resourceInfo,
3737
@Nullable Throwable cause) {
38-
this(token, message, resourceInfo, cause, null);
38+
this(token, message, resourceInfo, cause, null, null);
3939
}
4040
/** Private constructor. Use {@link SpannerExceptionFactory} to create instances. */
4141
InstanceNotFoundException(
4242
DoNotConstructDirectly token,
4343
@Nullable String message,
4444
ResourceInfo resourceInfo,
4545
@Nullable Throwable cause,
46-
@Nullable ApiException apiException) {
47-
super(token, message, resourceInfo, cause, apiException);
46+
@Nullable ApiException apiException,
47+
@Nullable XGoogSpannerRequestId reqId) {
48+
super(token, message, resourceInfo, cause, apiException, reqId);
4849
}
4950
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ public class MissingDefaultSequenceKindException extends SpannerException {
3737
ErrorCode errorCode,
3838
String message,
3939
Throwable cause,
40-
@Nullable ApiException apiException) {
41-
super(token, errorCode, /*retryable = */ false, message, cause, apiException);
40+
@Nullable ApiException apiException,
41+
@Nullable XGoogSpannerRequestId reqId) {
42+
super(token, errorCode, /*retryable = */ false, message, cause, apiException, reqId);
4243
}
4344

4445
static boolean isMissingDefaultSequenceKindException(Throwable cause) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private static <R, M> Operation<R, M> failed(
8989
SpannerRpc rpc, String name, Status status, M metadata, Parser<R, M> parser, ApiClock clock) {
9090
SpannerException e =
9191
SpannerExceptionFactory.newSpannerException(
92-
ErrorCode.fromRpcStatus(status), status.getMessage(), null);
92+
ErrorCode.fromRpcStatus(status), status.getMessage(), (Throwable) (null));
9393
return new Operation<>(rpc, name, metadata, null, e, true, parser, clock);
9494
}
9595

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,10 @@ private void backoffSleep(Context context, long backoffMillis) throws SpannerExc
180180
}
181181
if (latch.await(backoffMillis, TimeUnit.MILLISECONDS)) {
182182
// Woken by context cancellation.
183-
throw newSpannerExceptionForCancellation(context, null);
183+
throw newSpannerExceptionForCancellation(context, null, null /*TODO: requestId*/);
184184
}
185185
} catch (InterruptedException interruptExcept) {
186-
throw newSpannerExceptionForCancellation(context, interruptExcept);
186+
throw newSpannerExceptionForCancellation(context, interruptExcept, null /*TODO: requestId*/);
187187
} finally {
188188
context.removeListener(listener);
189189
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class SessionNotFoundException extends ResourceNotFoundException {
3535
@Nullable String message,
3636
ResourceInfo resourceInfo,
3737
@Nullable Throwable cause) {
38-
this(token, message, resourceInfo, cause, null);
38+
this(token, message, resourceInfo, cause, null, null);
3939
}
4040

4141
/** Private constructor. Use {@link SpannerExceptionFactory} to create instances. */
@@ -44,7 +44,8 @@ public class SessionNotFoundException extends ResourceNotFoundException {
4444
@Nullable String message,
4545
ResourceInfo resourceInfo,
4646
@Nullable Throwable cause,
47-
@Nullable ApiException apiException) {
48-
super(token, message, resourceInfo, cause, apiException);
47+
@Nullable ApiException apiException,
48+
@Nullable XGoogSpannerRequestId reqId) {
49+
super(token, message, resourceInfo, cause, apiException, reqId);
4950
}
5051
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ public static <T> T getOrNull(ApiFuture<T> future) throws SpannerException {
3535
}
3636
throw SpannerExceptionFactory.newSpannerException(e.getCause());
3737
} catch (InterruptedException e) {
38-
throw SpannerExceptionFactory.propagateInterrupt(e);
38+
throw SpannerExceptionFactory.propagateInterrupt(e, null /*TODO: requestId*/);
3939
} catch (CancellationException e) {
40-
throw SpannerExceptionFactory.newSpannerExceptionForCancellation(null, e);
40+
throw SpannerExceptionFactory.newSpannerExceptionForCancellation(
41+
null, e, null /*TODO: requestId*/);
4142
}
4243
}
4344
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ public class SpannerBatchUpdateException extends SpannerException {
2525
ErrorCode code,
2626
String message,
2727
long[] counts,
28-
Throwable cause) {
29-
super(token, code, false, message, cause);
28+
Throwable cause,
29+
XGoogSpannerRequestId reqId) {
30+
super(token, code, false, message, cause, null, reqId);
3031
updateCounts = counts;
3132
}
3233

0 commit comments

Comments
 (0)