Skip to content

Commit ae9b97a

Browse files
committed
change msg error
1 parent bd30e96 commit ae9b97a

File tree

3 files changed

+13
-25
lines changed

3 files changed

+13
-25
lines changed

aws_lambda_powertools/utilities/batch/decorators.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ def handler(event, context):
206206
try:
207207
records: list[dict] = event.get("Records", [])
208208
if not records or not isinstance(records, list):
209-
raise UnexpectedBatchTypeError
209+
raise UnexpectedBatchTypeError(
210+
"Unexpected batch event type. Possible values are: SQS, KinesisDataStreams, DynamoDBStreams",
211+
)
210212

211213
except AttributeError:
212214
event_types = ", ".join(list(EventType.__members__))
@@ -273,7 +275,9 @@ def handler(event, context):
273275
try:
274276
records: list[dict] = event.get("Records", [])
275277
if not records or not isinstance(records, list):
276-
raise UnexpectedBatchTypeError
278+
raise UnexpectedBatchTypeError(
279+
"Unexpected batch event type. Possible values are: SQS, KinesisDataStreams, DynamoDBStreams",
280+
)
277281

278282
except AttributeError:
279283
event_types = ", ".join(list(EventType.__members__))

aws_lambda_powertools/utilities/batch/exceptions.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ def __str__(self):
4141
class UnexpectedBatchTypeError(BatchProcessingError):
4242
"""Error thrown by the Batch Processing utility when a partial processor receives an unexpected batch type"""
4343

44-
def __init__(self):
45-
msg = "Unexpected batch type. Possible values are: SQS, KinesisDataStreams, DynamoDBStreams"
46-
super().__init__(msg)
47-
self.name = "UnexpectedBatchTypeError"
44+
pass
4845

4946

5047
class SQSFifoCircuitBreakerError(Exception):

tests/functional/batch/required_dependencies/test_utilities_batch.py

+6-19
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,9 @@ def test_process_partial_response_raises_unexpected_batch_type(event, record_han
731731
)
732732

733733
# THEN the correct error message is raised
734-
assert "Unexpected batch type. Possible values are: SQS, KinesisDataStreams, DynamoDBStreams" in str(exc_info.value)
734+
assert "Unexpected batch event type. Possible values are: SQS, KinesisDataStreams, DynamoDBStreams" in str(
735+
exc_info.value,
736+
)
735737

736738

737739
@pytest.mark.asyncio
@@ -756,21 +758,6 @@ async def test_async_process_partial_response_raises_unexpected_batch_type(event
756758
)
757759

758760
# THEN the correct error message is raised
759-
assert "Unexpected batch type. Possible values are: SQS, KinesisDataStreams, DynamoDBStreams" in str(exc_info.value)
760-
761-
762-
def test_process_partial_response_should_not_raise_unexpected_batch_type(record_handler):
763-
# GIVEN a valid SQS event structure
764-
event = {"Records": [{"messageId": "1", "body": "test"}]}
765-
processor = BatchProcessor(event_type=EventType.SQS)
766-
767-
# WHEN processing the event
768-
try:
769-
process_partial_response(
770-
event=event,
771-
record_handler=record_handler,
772-
processor=processor,
773-
)
774-
except UnexpectedBatchTypeError:
775-
# THEN no UnexpectedBatchTypeError should be raised
776-
pytest.fail("UnexpectedBatchTypeError was raised with a valid event structure!")
761+
assert "Unexpected batch event type. Possible values are: SQS, KinesisDataStreams, DynamoDBStreams" in str(
762+
exc_info.value,
763+
)

0 commit comments

Comments
 (0)