Skip to content

Commit 6236f11

Browse files
Rework to avoid placeholder type
1 parent 9750c07 commit 6236f11

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

localstack-core/localstack/aws/handlers/logging.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Handlers for logging."""
22

33
import logging
4-
import types
54
from functools import cached_property
65

76
from localstack.aws.api import RequestContext, ServiceException
@@ -22,17 +21,17 @@ class ExceptionLogger(ExceptionHandler):
2221
def __init__(self, logger=None):
2322
self.logger = logger or LOG
2423

25-
self._moto_service_exception = types.EllipsisType
26-
self._moto_rest_error = types.EllipsisType
27-
2824
try:
2925
import moto.core.exceptions
3026

31-
self._moto_service_exception = moto.core.exceptions.ServiceException
32-
self._moto_rest_error = moto.core.exceptions.RESTError
27+
self._skip_exceptions(
28+
ServiceException,
29+
moto.core.exceptions.ServiceException,
30+
moto.core.exceptions.RESTError,
31+
)
3332
except (ModuleNotFoundError, AttributeError):
3433
# Moto may not be available in stripped-down versions of LocalStack, like LocalStack S3 image.
35-
pass
34+
self._skip_exceptions = (ServiceException,)
3635

3736
def __call__(
3837
self,
@@ -41,13 +40,12 @@ def __call__(
4140
context: RequestContext,
4241
response: Response,
4342
):
44-
if isinstance(
45-
exception, (ServiceException, self._moto_service_exception, self._moto_rest_error)
46-
):
43+
if isinstance(exception, self._skip_exceptions):
4744
# We do not want to log an error/stacktrace if the handler is working as expected, but chooses to throw
4845
# a service exception. It may also throw a Moto ServiceException, which should not be logged either
4946
# because ServiceExceptionHandler understands it.
5047
return
48+
5149
if self.logger.isEnabledFor(level=logging.DEBUG):
5250
self.logger.exception("exception during call chain", exc_info=exception)
5351
else:

0 commit comments

Comments
 (0)