Skip to content

Commit b76d213

Browse files
committed
Fix formatting.
1 parent e88faa9 commit b76d213

3 files changed

Lines changed: 30 additions & 13 deletions

File tree

src/aws_durable_execution_sdk_python/exceptions.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,14 @@ def from_exception(cls, exception: Exception) -> Self:
146146
response = getattr(exception, "response", {})
147147
response_metadata = response.get("ResponseMetadata")
148148
error = response.get("Error")
149-
error_category = BotoClientError._classify_error_category(error, response_metadata)
149+
error_category = BotoClientError._classify_error_category(
150+
error, response_metadata
151+
)
150152
return cls(
151-
message=str(exception), error_category=error_category, error=error, response_metadata=response_metadata
153+
message=str(exception),
154+
error_category=error_category,
155+
error=error,
156+
response_metadata=response_metadata,
152157
)
153158

154159
@staticmethod
@@ -171,15 +176,19 @@ def _classify_error_category(
171176
if error_code and error_code in _NON_RETRYABLE_CUSTOMER_ERROR_CODES:
172177
return DurableApiErrorCategory.EXECUTION
173178

174-
status_code: int | None = (response_metadata and response_metadata.get("HTTPStatusCode")) or None
179+
status_code: int | None = (
180+
response_metadata and response_metadata.get("HTTPStatusCode")
181+
) or None
175182
if (
176183
status_code
177184
and BAD_REQUEST_ERROR <= status_code < SERVICE_ERROR
178185
and status_code != TOO_MANY_REQUESTS_ERROR
179186
and error
180187
and not (
181188
(error.get("Code") or "") == INVALID_PARAMETER_VALUE_EXCEPTION
182-
and (error.get("Message") or "").startswith(INVALID_CHECKPOINT_TOKEN_PREFIX)
189+
and (error.get("Message") or "").startswith(
190+
INVALID_CHECKPOINT_TOKEN_PREFIX
191+
)
183192
)
184193
):
185194
return DurableApiErrorCategory.EXECUTION

tests/exceptions_test.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,15 @@ def test_checkpoint_error_classification_invalid_param_without_token_execution()
123123
"KMSNotFoundException",
124124
],
125125
)
126-
def test_durable_api_error_non_retryable_customer_error_codes(error_cls, error_code: str):
126+
def test_durable_api_error_non_retryable_customer_error_codes(
127+
error_cls, error_code: str
128+
):
127129
"""Test that non-retryable customer error codes (HTTP 502) are classified as EXECUTION."""
128130
error_response = {
129131
"Error": {"Code": error_code, "Message": f"{error_code} error"},
130132
"ResponseMetadata": {"HTTPStatusCode": 502},
131133
}
132-
client_error = ClientError(error_response, "Invoke")
134+
client_error = ClientError(error_response, "Invoke") # type: ignore[arg-type]
133135
result = error_cls.from_exception(client_error)
134136
assert result.error_category == DurableApiErrorCategory.EXECUTION
135137
assert not result.is_retryable()
@@ -443,13 +445,15 @@ def test_orphaned_child_exception_with_operation_id():
443445
("ServiceException", 502, True),
444446
],
445447
)
446-
def test_boto_client_error_is_retryable(error_code: str, status_code: int, expected_retryable: bool):
448+
def test_boto_client_error_is_retryable(
449+
error_code: str, status_code: int, expected_retryable: bool
450+
):
447451
"""Test BotoClientError.is_retryable() classification."""
448452
error_response = {
449453
"Error": {"Code": error_code, "Message": "test error"},
450454
"ResponseMetadata": {"HTTPStatusCode": status_code},
451455
}
452-
client_error = ClientError(error_response, "Invoke")
456+
client_error = ClientError(error_response, "Invoke") # type: ignore[arg-type]
453457
result = BotoClientError.from_exception(client_error)
454458
assert result.is_retryable() == expected_retryable
455459

@@ -480,4 +484,4 @@ def test_durable_api_error_category_backward_compatible_alias():
480484
def test_invocation_error_is_retryable_default():
481485
"""Test InvocationError.is_retryable() returns True by default."""
482486
error = InvocationError("some error")
483-
assert error.is_retryable()
487+
assert error.is_retryable()

tests/execution_test.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2667,7 +2667,9 @@ def _make_invocation_input(mock_client, next_marker=""):
26672667
return DurableExecutionInvocationInputWithClient(
26682668
durable_execution_arn="arn:test:execution",
26692669
checkpoint_token="token123", # noqa: S106
2670-
initial_execution_state=InitialExecutionState(operations=[operation], next_marker=next_marker),
2670+
initial_execution_state=InitialExecutionState(
2671+
operations=[operation], next_marker=next_marker
2672+
),
26712673
service_client=mock_client,
26722674
)
26732675

@@ -2729,7 +2731,9 @@ def test_durable_execution_non_retryable_background_thread_error_returns_failed(
27292731
error={"Code": "KMSDisabledException", "Message": "KMS key disabled"},
27302732
response_metadata={"HTTPStatusCode": 502},
27312733
)
2732-
mock_client.checkpoint.side_effect = lambda *a, **kw: (_ for _ in ()).throw(non_retryable_error)
2734+
mock_client.checkpoint.side_effect = lambda *a, **kw: (_ for _ in ()).throw(
2735+
non_retryable_error
2736+
)
27332737

27342738
@durable_execution
27352739
def test_handler(event: Any, context: DurableContext) -> dict:
@@ -2757,7 +2761,7 @@ def test_durable_execution_non_retryable_initial_pagination_error_returns_failed
27572761
message=f"{error_code} error",
27582762
error_category=error_category,
27592763
error={"Code": error_code, "Message": f"{error_code} error"},
2760-
response_metadata={"HTTPStatusCode": status_code},
2764+
response_metadata={"HTTPStatusCode": status_code}, # type: ignore[arg-type]
27612765
)
27622766
mock_client.get_execution_state.side_effect = non_retryable_error
27632767

@@ -2791,4 +2795,4 @@ def test_handler(event: Any, context: DurableContext) -> dict:
27912795
test_handler(
27922796
_make_invocation_input(mock_client, next_marker="next-page-marker"),
27932797
_make_lambda_context(),
2794-
)
2798+
)

0 commit comments

Comments
 (0)