Skip to content

Commit 70100ee

Browse files
committed
Make get_error_info optional
1 parent 9e37c52 commit 70100ee

File tree

3 files changed

+25
-15
lines changed

3 files changed

+25
-15
lines changed

packages/smithy-core/src/smithy_core/aio/client.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from collections.abc import Awaitable, Callable, Sequence
77
from copy import copy
88
from dataclasses import dataclass, field, replace
9-
from typing import TYPE_CHECKING, Any
9+
from typing import TYPE_CHECKING, Any, cast
1010

1111
from .. import URI
1212
from ..auth import AuthParams
@@ -32,6 +32,7 @@
3232
ClientProtocol,
3333
ClientTransport,
3434
EndpointResolver,
35+
ErrorClassifyingTransport,
3536
Request,
3637
Response,
3738
)
@@ -468,11 +469,15 @@ async def _handle_attempt[I: SerializeableShape, O: DeserializeableShape](
468469
request=request_context.transport_request
469470
)
470471
except Exception as e:
471-
error_info = self.transport.get_error_info(e)
472-
if error_info.is_timeout_error:
473-
raise ClientTimeoutError(
474-
message=f"Client timeout occurred: {e}"
475-
) from e
472+
if hasattr(self.transport, "get_error_info"):
473+
classifying_transport = cast(
474+
ErrorClassifyingTransport[TRequest, TResponse], self.transport
475+
)
476+
error_info = classifying_transport.get_error_info(e)
477+
if error_info.is_timeout_error:
478+
raise ClientTimeoutError(
479+
message=f"Client timeout occurred: {e}"
480+
) from e
476481
raise
477482

478483
_LOGGER.debug("Received response: %s", transport_response)

packages/smithy-core/src/smithy_core/aio/interfaces/__init__.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,20 @@ async def resolve_endpoint(self, params: EndpointResolverParams[Any]) -> Endpoin
9696

9797

9898
class ClientTransport[I: Request, O: Response](Protocol):
99-
"""Protocol-agnostic representation of a client transport (e.g. an HTTP client).
99+
"""Protocol-agnostic representation of a client transport (e.g. an HTTP client)."""
100100

101-
Transport implementations must define the get_error_info method to determine which
102-
exceptions represent timeout conditions for that transport.
101+
async def send(self, request: I) -> O:
102+
"""Send a request over the transport and receive the response."""
103+
...
104+
105+
106+
class ErrorClassifyingTransport[I: Request, O: Response](
107+
ClientTransport[I, O], Protocol
108+
):
109+
"""A client transport that can classify errors for retry and timeout detection.
110+
111+
Transport implementations should implement this protocol if they can determine
112+
which exceptions represent timeout conditions or other classifiable error types.
103113
"""
104114

105115
def get_error_info(self, exception: Exception, **kwargs: Any) -> ClientErrorInfo:
@@ -110,14 +120,10 @@ def get_error_info(self, exception: Exception, **kwargs: Any) -> ClientErrorInfo
110120
**kwargs: Additional context for analysis
111121
112122
Returns:
113-
ClientErrorInfo with timeout information.
123+
ClientErrorInfo with error classification details.
114124
"""
115125
...
116126

117-
async def send(self, request: I) -> O:
118-
"""Send a request over the transport and receive the response."""
119-
...
120-
121127

122128
class ClientProtocol[I: Request, O: Response](Protocol):
123129
"""A protocol used by a client to communicate with a server."""

packages/smithy-http/tests/unit/aio/test_protocols.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ def test_http_protocol_joins_uris(
139139
assert actual == expected
140140

141141

142-
@pytest.mark.asyncio
143142
async def test_http_408_creates_timeout_error() -> None:
144143
protocol = Mock(spec=HttpBindingClientProtocol)
145144
protocol.error_identifier = Mock()

0 commit comments

Comments
 (0)