diff --git a/airbyte-cdk/python/airbyte_cdk/sources/streams/concurrent/exceptions.py b/airbyte-cdk/python/airbyte_cdk/sources/streams/concurrent/exceptions.py index c67c2c58311d1..a0cf699a46d0d 100644 --- a/airbyte-cdk/python/airbyte_cdk/sources/streams/concurrent/exceptions.py +++ b/airbyte-cdk/python/airbyte_cdk/sources/streams/concurrent/exceptions.py @@ -13,3 +13,6 @@ class ExceptionWithDisplayMessage(Exception): def __init__(self, display_message: str, **kwargs: Any): super().__init__(**kwargs) self.display_message = display_message + + def __str__(self) -> str: + return f'ExceptionWithDisplayMessage: "{self.display_message}"' diff --git a/airbyte-cdk/python/unit_tests/test_exception_handler.py b/airbyte-cdk/python/unit_tests/test_exception_handler.py index 3c6466dd46c74..42819942ade19 100644 --- a/airbyte-cdk/python/unit_tests/test_exception_handler.py +++ b/airbyte-cdk/python/unit_tests/test_exception_handler.py @@ -10,6 +10,7 @@ import pytest from airbyte_cdk.exception_handler import assemble_uncaught_exception from airbyte_cdk.models import AirbyteErrorTraceMessage, AirbyteLogMessage, AirbyteMessage, AirbyteTraceMessage +from airbyte_cdk.sources.streams.concurrent.exceptions import ExceptionWithDisplayMessage from airbyte_cdk.utils.traced_exception import AirbyteTracedException @@ -25,6 +26,13 @@ def test_given_exception_not_traced_exception_when_assemble_uncaught_exception_t assert isinstance(assembled_exception, AirbyteTracedException) +def test_given_exception_with_display_message_when_assemble_uncaught_exception_then_internal_message_contains_display_message(): + display_message = "some display message" + exception = ExceptionWithDisplayMessage(display_message) + assembled_exception = assemble_uncaught_exception(type(exception), exception) + assert display_message in assembled_exception.internal_message + + def test_uncaught_exception_handler(): cmd = "from airbyte_cdk.logger import init_logger; from airbyte_cdk.exception_handler import init_uncaught_exception_handler; logger = init_logger('airbyte'); init_uncaught_exception_handler(logger); raise 1" exception_message = "exceptions must derive from BaseException"