1414import sys
1515from abc import ABC , abstractmethod
1616from enum import Enum
17- from typing import TYPE_CHECKING , Any , Tuple , Union , overload
17+ from typing import TYPE_CHECKING , Any , Tuple , TypeGuard , Union , overload
1818
1919from aws_lambda_powertools .shared import constants
2020from aws_lambda_powertools .utilities .batch .exceptions import (
3535
3636if TYPE_CHECKING :
3737 from collections .abc import Callable
38+ from types import TracebackType
3839
3940 from aws_lambda_powertools .utilities .batch .types import (
4041 PartialItemFailureResponse ,
@@ -61,6 +62,10 @@ class EventType(Enum):
6162FailureResponse = Tuple [str , str , BatchEventTypes ]
6263
6364
65+ def _has_traceback (exception : ExceptionInfo ) -> TypeGuard [tuple [type [BaseException ], BaseException , TracebackType ]]:
66+ return exception [0 ] is not None and exception [1 ] is not None and exception [2 ] is not None
67+
68+
6469class BasePartialProcessor (ABC ):
6570 """
6671 Abstract class for batch processors.
@@ -239,15 +244,10 @@ def failure_handler(self, record, exception: ExceptionInfo) -> FailureResponse:
239244 entry = ("fail" , exception_string , record )
240245 logger .debug (f"Record processing exception: { exception_string } " )
241246
242- if (
243- self .logger is not None
244- and exception [0 ] is not None
245- and exception [1 ] is not None
246- and exception [2 ] is not None
247- ):
247+ if self .logger is not None and _has_traceback (exception ):
248248 self .logger .warning (
249249 "Record processing exception; skipping this record" ,
250- exc_info = ( exception [ 0 ], exception [ 1 ], exception [ 2 ]) ,
250+ exc_info = exception ,
251251 )
252252
253253 self .exceptions .append (exception )
0 commit comments