module documentation

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

This module uses request_status to represent detailed service errors. It uses service semantics and gRPC status codes to decide if a request can retry.

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_str Render a ServiceError as a short 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
Constant _SERVICE_ERROR_NAMES 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_str(err: Any) -> str: (source)

Render a ServiceError as a short 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})',
...
_SERVICE_ERROR_NAMES = (source)

Undocumented

Value
frozenset(set(['nebius.common.v1.ServiceError',
               'nebius.common.error.v1alpha1.ServiceError']))