diff --git a/tests/unit/test_middleware/test_exception_handler_middleware.py b/tests/unit/test_middleware/test_exception_handler_middleware.py index ba842d3952..7f2cae85d1 100644 --- a/tests/unit/test_middleware/test_exception_handler_middleware.py +++ b/tests/unit/test_middleware/test_exception_handler_middleware.py @@ -1,3 +1,4 @@ +from inspect import getinnerframes from typing import TYPE_CHECKING, Any, Callable, Optional import pytest @@ -10,6 +11,7 @@ from litestar.exceptions import HTTPException, InternalServerException, ValidationException from litestar.logging.config import LoggingConfig, StructLoggingConfig from litestar.middleware.exceptions import ExceptionHandlerMiddleware +from litestar.middleware.exceptions._debug_response import get_symbol_name from litestar.middleware.exceptions.middleware import get_exception_handler from litestar.status_codes import HTTP_400_BAD_REQUEST, HTTP_500_INTERNAL_SERVER_ERROR from litestar.testing import TestClient, create_test_client @@ -340,3 +342,23 @@ def handler() -> None: assert caplog.records[0].message.startswith( "exception raised on http connection to route /test\n\nTraceback (most recent call last):\n" ) + + +def test_get_symbol_name_where_type_doesnt_support_bool() -> None: + class Test: + def __bool__(self) -> bool: + raise TypeError("This type doesn't support bool") + + def method(self) -> None: + raise RuntimeError("Oh no!") + + exc = None + + try: + Test().method() + except Exception as e: + exc = e + + if exc is not None and exc.__traceback__ is not None: + frame = getinnerframes(exc.__traceback__, 2)[-1] + assert get_symbol_name(frame) == "Test.method"