Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit fdc2e3b

Browse files
committed
improved exception parsing
1 parent 1a08f1a commit fdc2e3b

1 file changed

Lines changed: 9 additions & 12 deletions

File tree

google/cloud/bigtable/data/_metrics/data_model.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
from dataclasses import field
2828
from grpc import StatusCode
2929

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
3333
from google.cloud.bigtable.data._helpers import _retry_exception_factory
3434
from google.cloud.bigtable_v2.types.response_params import ResponseParams
3535
from google.protobuf.message import DecodeError
@@ -429,15 +429,12 @@ def _exc_to_status(exc: Exception) -> StatusCode:
429429
- exc: The exception to extract the status code from.
430430
"""
431431
# 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__)
441438
# parse grpc exceptions
442439
if hasattr(exc, "grpc_status_code") and exc.grpc_status_code is not None:
443440
return exc.grpc_status_code

0 commit comments

Comments
 (0)