@@ -58,12 +58,18 @@ public final class SpannerExceptionFactory {
58
58
ProtoUtils .keyForProto (ErrorInfo .getDefaultInstance ());
59
59
60
60
public static SpannerException newSpannerException (ErrorCode code , @ Nullable String message ) {
61
- return newSpannerException (code , message , null );
61
+ return newSpannerException (code , message , (XGoogSpannerRequestId ) (null ));
62
+ }
63
+
64
+ public static SpannerException newSpannerException (
65
+ ErrorCode code , @ Nullable String message , @ Nullable XGoogSpannerRequestId reqId ) {
66
+ return newSpannerExceptionPreformatted (
67
+ code , formatMessage (code , message ), (Throwable ) (null ), (ApiException ) (null ), reqId );
62
68
}
63
69
64
70
public static SpannerException newSpannerException (
65
71
ErrorCode code , @ Nullable String message , @ Nullable Throwable cause ) {
66
- return newSpannerExceptionPreformatted (code , formatMessage (code , message ), cause );
72
+ return newSpannerExceptionPreformatted (code , formatMessage (code , message ), cause , null , null );
67
73
}
68
74
69
75
public static SpannerException propagateInterrupt (InterruptedException e ) {
@@ -115,12 +121,17 @@ public static SpannerException newSpannerException(Throwable cause) {
115
121
return newSpannerException (null , cause );
116
122
}
117
123
124
+ public static SpannerException newSpannerException (
125
+ Throwable cause , XGoogSpannerRequestId requestId ) {
126
+ return newSpannerExceptionPreformatted (null , null , cause , null , requestId );
127
+ }
128
+
118
129
public static SpannerBatchUpdateException newSpannerBatchUpdateException (
119
130
ErrorCode code , String message , long [] updateCounts ) {
120
131
DoNotConstructDirectly token = DoNotConstructDirectly .ALLOWED ;
121
132
SpannerException cause = null ;
122
133
if (isTransactionMutationLimitException (code , message )) {
123
- cause = new TransactionMutationLimitExceededException (token , code , message , null , null );
134
+ cause = new TransactionMutationLimitExceededException (token , code , message , null , null , null );
124
135
}
125
136
return new SpannerBatchUpdateException (token , code , message , updateCounts , cause );
126
137
}
@@ -305,7 +316,8 @@ static SpannerException newSpannerExceptionPreformatted(
305
316
ErrorCode code ,
306
317
@ Nullable String message ,
307
318
@ Nullable Throwable cause ,
308
- @ Nullable ApiException apiException ) {
319
+ @ Nullable ApiException apiException ,
320
+ @ Nullable XGoogSpannerRequestId reqId ) {
309
321
// This is the one place in the codebase that is allowed to call constructors directly.
310
322
DoNotConstructDirectly token = DoNotConstructDirectly .ALLOWED ;
311
323
switch (code ) {
@@ -319,41 +331,44 @@ static SpannerException newSpannerExceptionPreformatted(
319
331
&& AdminRequestsPerMinuteExceededException .ADMIN_REQUESTS_LIMIT_VALUE .equals (
320
332
info .getMetadataMap ()
321
333
.get (AdminRequestsPerMinuteExceededException .ADMIN_REQUESTS_LIMIT_KEY ))) {
322
- return new AdminRequestsPerMinuteExceededException (token , message , cause , apiException );
334
+ return new AdminRequestsPerMinuteExceededException (
335
+ token , message , cause , apiException , reqId );
323
336
}
324
337
case NOT_FOUND :
325
338
ResourceInfo resourceInfo = extractResourceInfo (cause );
326
339
if (resourceInfo != null ) {
327
340
switch (resourceInfo .getResourceType ()) {
328
341
case SESSION_RESOURCE_TYPE :
329
342
return new SessionNotFoundException (
330
- token , message , resourceInfo , cause , apiException );
343
+ token , message , resourceInfo , cause , apiException , reqId );
331
344
case DATABASE_RESOURCE_TYPE :
332
345
return new DatabaseNotFoundException (
333
- token , message , resourceInfo , cause , apiException );
346
+ token , message , resourceInfo , cause , apiException , reqId );
334
347
case INSTANCE_RESOURCE_TYPE :
335
348
return new InstanceNotFoundException (
336
- token , message , resourceInfo , cause , apiException );
349
+ token , message , resourceInfo , cause , apiException , reqId );
337
350
}
338
351
}
339
352
case INVALID_ARGUMENT :
340
353
if (isTransactionMutationLimitException (cause )) {
341
354
return new TransactionMutationLimitExceededException (
342
- token , code , message , cause , apiException );
355
+ token , code , message , cause , apiException , reqId );
343
356
}
344
357
if (isMissingDefaultSequenceKindException (apiException )) {
345
- return new MissingDefaultSequenceKindException (token , code , message , cause , apiException );
358
+ return new MissingDefaultSequenceKindException (
359
+ token , code , message , cause , apiException , reqId );
346
360
}
347
361
// Fall through to the default.
348
362
default :
349
363
return new SpannerException (
350
- token , code , isRetryable (code , cause ), message , cause , apiException );
364
+ token , code , isRetryable (code , cause ), message , cause , apiException , reqId );
351
365
}
352
366
}
353
367
354
368
static SpannerException newSpannerExceptionPreformatted (
355
369
ErrorCode code , @ Nullable String message , @ Nullable Throwable cause ) {
356
- return newSpannerExceptionPreformatted (code , message , cause , null );
370
+ return newSpannerExceptionPreformatted (
371
+ code , message , cause , null , (XGoogSpannerRequestId ) (null ));
357
372
}
358
373
359
374
private static SpannerException fromApiException (ApiException exception ) {
@@ -371,7 +386,8 @@ private static SpannerException fromApiException(ApiException exception) {
371
386
errorCode ,
372
387
formatMessage (errorCode , exception .getMessage ()),
373
388
exception .getCause (),
374
- exception );
389
+ exception ,
390
+ null );
375
391
}
376
392
377
393
private static boolean isRetryable (ErrorCode code , @ Nullable Throwable cause ) {
0 commit comments