|
27 | 27 | from dataclasses import field |
28 | 28 | from grpc import StatusCode |
29 | 29 |
|
30 | | -from google.cloud.bigtable.data.exceptions import MutationsExceptionGroup |
31 | | -from google.cloud.bigtable.data.exceptions import ShardedReadRowsExceptionGroup |
32 | | -from google.cloud.bigtable.data.exceptions import RetryExceptionGroup |
| 30 | +from google.cloud.bigtable.data.exceptions import FailedQueryShardError |
| 31 | +from google.cloud.bigtable.data.exceptions import FailedMutationEntryError |
| 32 | +from google.cloud.bigtable.data.exceptions import _BigtableExceptionGroup |
33 | 33 | from google.cloud.bigtable.data._helpers import _retry_exception_factory |
34 | 34 | from google.cloud.bigtable_v2.types.response_params import ResponseParams |
35 | 35 | from google.protobuf.message import DecodeError |
@@ -429,15 +429,12 @@ def _exc_to_status(exc: Exception) -> StatusCode: |
429 | 429 | - exc: The exception to extract the status code from. |
430 | 430 | """ |
431 | 431 | # parse bigtable custom exceptions |
432 | | - if ( |
433 | | - isinstance(exc, (MutationsExceptionGroup, ShardedReadRowsExceptionGroup)) |
434 | | - and exc.exceptions |
435 | | - ): |
436 | | - # grab the RetryExceptionGroup from the most last failed mutation/shard |
437 | | - exc = exc.exceptions[-1].__cause__ |
438 | | - if isinstance(exc, RetryExceptionGroup): |
439 | | - # grab the last exception in the retry group |
440 | | - exc = exc.exceptions[-1] |
| 432 | + if isinstance(exc, _BigtableExceptionGroup) and exc.exceptions: |
| 433 | + # find most recent in group |
| 434 | + return ActiveOperationMetric._exc_to_status(exc.exceptions[-1]) |
| 435 | + if isinstance(exc, (FailedMutationEntryError, FailedQueryShardError)): |
| 436 | + # find cause of failed entries |
| 437 | + return ActiveOperationMetric._exc_to_status(exc.__cause__) |
441 | 438 | # parse grpc exceptions |
442 | 439 | if hasattr(exc, "grpc_status_code") and exc.grpc_status_code is not None: |
443 | 440 | return exc.grpc_status_code |
|
0 commit comments