module documentation

Helpers for converting service-level protobuf errors into SDK types.

This module builds on request_status to represent detailed service errors (ServiceError PBs) and to decide retriability based on service semantics and gRPC status codes.

Class RequestStatusExtended Extended request status that includes parsed service errors.
Exception RequestError Exception raised for requests that failed with service-level errors.
Function int_to_status_code Convert an integer or StatusCode into a StatusCode instance.
Function is_dns_error Return True when an exception indicates a DNS resolution problem.
Function is_network_error Return True for network errors that look like timeouts.
Function is_retriable_error Decide whether an exception should be retried.
Function is_transport_error Return True for transport-level errors such as connection reset.
Function to_anypb Pack a ServiceError protobuf into a google.protobuf.Any message.
Function to_str Render a ServiceError into a concise human readable string.
Variable code_map Undocumented
Variable DefaultRetriableCodes Undocumented
Function _call_error_method Undocumented
Function _grpc_error_has_unknown_http_52x_status Undocumented
Function _has_unexpected_http_52x_status Detect proxy-originated HTTP 52x statuses in Python gRPC messages.
Function _is_unknown_code Return True when a gRPC status code value represents UNKNOWN.
Function _iter_error_chain Undocumented
Constant _HTTP_STATUS_PATTERNS Undocumented
def int_to_status_code(i: int | StatusCode) -> StatusCode: (source)

Convert an integer or StatusCode into a StatusCode instance.

Useful when reading numeric status codes from protobuf messages.

def is_dns_error(err: Exception) -> bool: (source)

Return True when an exception indicates a DNS resolution problem.

def is_network_error(err: Exception) -> bool: (source)

Return True for network errors that look like timeouts.

def is_retriable_error(err: Exception, deadline_retriable: bool = False) -> bool: (source)

Decide whether an exception should be retried.

The function recognizes RequestError (service-level errors) and also checks for common network/transport error conditions.

def is_transport_error(err: Exception) -> bool: (source)

Return True for transport-level errors such as connection reset.

This is a heuristic based on the textual content of the exception.

def to_anypb(err: ServiceError) -> AnyPb: (source)

Pack a ServiceError protobuf into a google.protobuf.Any message.

This helper is used when converting SDK-level error representations back into gRPC status details.

def to_str(err: ServiceError) -> str: (source)

Render a ServiceError into a concise human readable string.

The function inspects typed details attached to the service error and produces a one-line summary intended for logs and exception messages.

code_map = (source)

Undocumented

DefaultRetriableCodes = (source)

Undocumented

def _call_error_method(err: BaseException, name: str) -> object | None: (source)

Undocumented

def _grpc_error_has_unknown_http_52x_status(err: BaseException) -> bool: (source)

Undocumented

def _has_unexpected_http_52x_status(message: str | None) -> bool: (source)

Detect proxy-originated HTTP 52x statuses in Python gRPC messages.

def _is_unknown_code(code: object) -> bool: (source)

Return True when a gRPC status code value represents UNKNOWN.

def _iter_error_chain(err: BaseException) -> Iterable[BaseException]: (source)

Undocumented

_HTTP_STATUS_PATTERNS = (source)

Undocumented

Value
[re.compile(r'\bunexpected\s+http\s+status(?:\s+code)?(?:\s+received\s+from\s+se
rver)?\s*[:=]?\s*(?P<code>\d{3})',
            re.IGNORECASE),
 re.compile(r'\breceived\s+http2?\s+header\s+with\s+status\s*[:=]?\s*(?P<code>\d
{3})',
            re.IGNORECASE),
 re.compile(r'\bhttp(?:/2|2)?\s+status(?:\s+code)?\s*[:=]?\s*(?P<code>\d{3})',
...