Skip to content

Commit 9724775

Browse files
author
Sujit
committed
chore: simplify batch logger warning guard
1 parent 40ec3f0 commit 9724775

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

  • aws_lambda_powertools/utilities/batch

aws_lambda_powertools/utilities/batch/base.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import sys
1515
from abc import ABC, abstractmethod
1616
from 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

1919
from aws_lambda_powertools.shared import constants
2020
from aws_lambda_powertools.utilities.batch.exceptions import (
@@ -35,6 +35,7 @@
3535

3636
if 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):
6162
FailureResponse = 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+
6469
class 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

Comments
 (0)