Skip to content

Commit e2eaf9d

Browse files
Move error retry info to retries interfaces
1 parent a493125 commit e2eaf9d

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

designs/exceptions.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ implement.
4040
```python
4141
@dataclass(kw_only=True)
4242
@runtime_checkable
43-
class RetryInfo(Protocol):
43+
class ErrorRetryInfo(Protocol):
4444
is_retry_safe: bool | None = None
4545
"""Whether the exception is safe to retry.
4646

packages/smithy-core/src/smithy_core/exceptions.py

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33
from dataclasses import dataclass, field
4-
from typing import Literal, Protocol, runtime_checkable
4+
from typing import Literal
55

66

77
class SmithyException(Exception):
@@ -16,8 +16,21 @@ class SmithyException(Exception):
1616

1717

1818
@dataclass(kw_only=True)
19-
@runtime_checkable
20-
class RetryInfo(Protocol):
19+
class CallException(SmithyException):
20+
"""Base exception to be used in application-level errors.
21+
22+
Implements :py:class:`.interfaces.retries.ErrorRetryInfo`.
23+
"""
24+
25+
fault: Fault = None
26+
"""Whether the client or server is at fault.
27+
28+
If None, then there was not enough information to determine fault.
29+
"""
30+
31+
message: str = field(default="", kw_only=False)
32+
"""The message of the error."""
33+
2134
is_retry_safe: bool | None = None
2235
"""Whether the exception is safe to retry.
2336
@@ -37,20 +50,6 @@ class RetryInfo(Protocol):
3750
is_throttle: bool = False
3851
"""Whether the error is a throttling error."""
3952

40-
41-
@dataclass(kw_only=True)
42-
class CallException(SmithyException, RetryInfo):
43-
"""Base exception to be used in application-level errors."""
44-
45-
fault: Fault = None
46-
"""Whether the client or server is at fault.
47-
48-
If None, then there was not enough information to determine fault.
49-
"""
50-
51-
message: str = field(default="", kw_only=False)
52-
"""The message of the error."""
53-
5453
def __post_init__(self):
5554
super().__init__(self.message)
5655

packages/smithy-core/src/smithy_core/interfaces/retries.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,31 @@
22
# SPDX-License-Identifier: Apache-2.0
33
from dataclasses import dataclass
44
from enum import Enum
5-
from typing import Protocol
5+
from typing import Protocol, runtime_checkable
6+
7+
8+
@runtime_checkable
9+
class ErrorRetryInfo(Protocol):
10+
"""A protocol for exceptions that have retry information embedded."""
11+
12+
is_retry_safe: bool | None = None
13+
"""Whether the exception is safe to retry.
14+
15+
A value of True does not mean a retry will occur, but rather that a retry is allowed
16+
to occur.
17+
18+
A value of None indicates that there is not enough information available to
19+
determine if a retry is safe.
20+
"""
21+
22+
retry_after: float | None = None
23+
"""The amount of time that should pass before a retry.
24+
25+
Retry strategies MAY choose to wait longer.
26+
"""
27+
28+
is_throttle: bool = False
29+
"""Whether the error is a throttling error."""
630

731

832
class RetryErrorType(Enum):

0 commit comments

Comments
 (0)