@@ -118,22 +118,23 @@ public static SpannerException asSpannerException(Throwable t) {
118118 * #newSpannerException(ErrorCode, String)} instead of this method.
119119 */
120120 public static SpannerException newSpannerException (Throwable cause ) {
121- return newSpannerException (null , cause );
121+ return newSpannerException (null , cause , null );
122122 }
123123
124124 public static SpannerException newSpannerException (
125125 Throwable cause , XGoogSpannerRequestId requestId ) {
126- return newSpannerExceptionPreformatted (null , null , cause , null , requestId );
126+ return newSpannerException (null , cause , requestId );
127127 }
128128
129129 public static SpannerBatchUpdateException newSpannerBatchUpdateException (
130- ErrorCode code , String message , long [] updateCounts ) {
130+ ErrorCode code , String message , long [] updateCounts , @ Nullable XGoogSpannerRequestId reqId ) {
131131 DoNotConstructDirectly token = DoNotConstructDirectly .ALLOWED ;
132132 SpannerException cause = null ;
133133 if (isTransactionMutationLimitException (code , message )) {
134- cause = new TransactionMutationLimitExceededException (token , code , message , null , null , null );
134+ cause =
135+ new TransactionMutationLimitExceededException (token , code , message , null , null , reqId );
135136 }
136- return new SpannerBatchUpdateException (token , code , message , updateCounts , cause );
137+ return new SpannerBatchUpdateException (token , code , message , updateCounts , cause , reqId );
137138 }
138139
139140 /** Constructs a specific error that */
@@ -191,21 +192,22 @@ public static SpannerBatchUpdateException newSpannerBatchUpdateException(
191192 * <p>Intended for internal library use; user code should use {@link
192193 * #newSpannerException(ErrorCode, String)} instead of this method.
193194 */
194- public static SpannerException newSpannerException (@ Nullable Context context , Throwable cause ) {
195+ public static SpannerException newSpannerException (
196+ @ Nullable Context context , Throwable cause , @ Nullable XGoogSpannerRequestId reqId ) {
195197 if (cause instanceof SpannerException ) {
196198 SpannerException e = (SpannerException ) cause ;
197- return newSpannerExceptionPreformatted (e .getErrorCode (), e .getMessage (), e );
199+ return newSpannerExceptionPreformatted (e .getErrorCode (), e .getMessage (), e , null , reqId );
198200 } else if (cause instanceof CancellationException ) {
199- return newSpannerExceptionForCancellation (context , cause );
201+ return newSpannerExceptionForCancellation (context , cause , reqId );
200202 } else if (cause instanceof ApiException ) {
201- return fromApiException ((ApiException ) cause );
203+ return fromApiException ((ApiException ) cause , reqId );
202204 }
203205 // Extract gRPC status. This will produce "UNKNOWN" for non-gRPC exceptions.
204206 Status status = Status .fromThrowable (cause );
205207 if (status .getCode () == Status .Code .CANCELLED ) {
206- return newSpannerExceptionForCancellation (context , cause );
208+ return newSpannerExceptionForCancellation (context , cause , reqId );
207209 }
208- return newSpannerException (ErrorCode .fromGrpcStatus (status ), cause .getMessage (), cause );
210+ return newSpannerException (ErrorCode .fromGrpcStatus (status ), cause .getMessage (), cause , reqId );
209211 }
210212
211213 public static RuntimeException causeAsRunTimeException (ExecutionException executionException ) {
@@ -229,7 +231,7 @@ static SpannerException newRetryOnDifferentGrpcChannelException(
229231 }
230232
231233 static SpannerException newSpannerExceptionForCancellation (
232- @ Nullable Context context , @ Nullable Throwable cause ) {
234+ @ Nullable Context context , @ Nullable Throwable cause , @ Nullable XGoogSpannerRequestId reqId ) {
233235 if (context != null && context .isCancelled ()) {
234236 Throwable cancellationCause = context .cancellationCause ();
235237 Throwable throwable =
@@ -238,9 +240,10 @@ static SpannerException newSpannerExceptionForCancellation(
238240 : MoreObjects .firstNonNull (cause , cancellationCause );
239241 if (cancellationCause instanceof TimeoutException ) {
240242 return newSpannerException (
241- ErrorCode .DEADLINE_EXCEEDED , "Current context exceeded deadline" , throwable );
243+ ErrorCode .DEADLINE_EXCEEDED , "Current context exceeded deadline" , throwable , reqId );
242244 } else {
243- return newSpannerException (ErrorCode .CANCELLED , "Current context was cancelled" , throwable );
245+ return newSpannerException (
246+ ErrorCode .CANCELLED , "Current context was cancelled" , throwable , reqId );
244247 }
245248 }
246249 return newSpannerException (
@@ -371,7 +374,8 @@ static SpannerException newSpannerExceptionPreformatted(
371374 code , message , cause , null , (XGoogSpannerRequestId ) (null ));
372375 }
373376
374- private static SpannerException fromApiException (ApiException exception ) {
377+ private static SpannerException fromApiException (
378+ ApiException exception , @ Nullable XGoogSpannerRequestId reqId ) {
375379 Status .Code code ;
376380 if (exception .getStatusCode () instanceof GrpcStatusCode ) {
377381 code = ((GrpcStatusCode ) exception .getStatusCode ()).getTransportCode ();
@@ -387,7 +391,7 @@ private static SpannerException fromApiException(ApiException exception) {
387391 formatMessage (errorCode , exception .getMessage ()),
388392 exception .getCause (),
389393 exception ,
390- null );
394+ reqId );
391395 }
392396
393397 private static boolean isRetryable (ErrorCode code , @ Nullable Throwable cause ) {
0 commit comments