Skip to content

chore(batch): safeguard custom use of BatchProcessingError exception #2155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions aws_lambda_powertools/utilities/batch/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""
Batch processing exceptions
"""
from __future__ import annotations

import traceback
from types import TracebackType
from typing import List, Optional, Tuple, Type
Expand All @@ -9,10 +11,10 @@


class BaseBatchProcessingError(Exception):
def __init__(self, msg="", child_exceptions: Optional[List[ExceptionInfo]] = None):
def __init__(self, msg="", child_exceptions: List[ExceptionInfo] | None = None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice to use new annotations :)

super().__init__(msg)
self.msg = msg
self.child_exceptions = child_exceptions
self.child_exceptions = child_exceptions or []

def format_exceptions(self, parent_exception_str):
exception_list = [f"{parent_exception_str}\n"]
Expand All @@ -27,7 +29,7 @@ def format_exceptions(self, parent_exception_str):
class BatchProcessingError(BaseBatchProcessingError):
"""When all batch records failed to be processed"""

def __init__(self, msg="", child_exceptions: Optional[List[ExceptionInfo]] = None):
def __init__(self, msg="", child_exceptions: List[ExceptionInfo] | None = None):
super().__init__(msg, child_exceptions)

def __str__(self):
Expand Down