Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Catch and surface BaseException() #1108

Merged
merged 3 commits into from Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -112,7 +112,7 @@ def _wrap_as_exception(maybe_exception: Any) -> BaseException:

def _wrap_callback_errors(
callback: Callable[["google.cloud.pubsub_v1.subscriber.message.Message"], Any],
on_callback_error: Callable[[Exception], Any],
on_callback_error: Callable[[BaseException], Any],
message: "google.cloud.pubsub_v1.subscriber.message.Message",
):
"""Wraps a user callback so that if an exception occurs the message is
Expand All @@ -124,7 +124,7 @@ def _wrap_callback_errors(
"""
try:
callback(message)
except Exception as exc:
except BaseException as exc:
# Note: the likelihood of this failing is extremely low. This just adds
# a message to a queue, so if this doesn't work the world is in an
# unrecoverable state and this thread should just bail.
Expand Down
11 changes: 8 additions & 3 deletions tests/unit/pubsub_v1/subscriber/test_streaming_pull_manager.py
Expand Up @@ -77,9 +77,14 @@ def test__wrap_callback_errors_no_error():
on_callback_error.assert_not_called()


def test__wrap_callback_errors_error():
callback_error = ValueError("meep")

@pytest.mark.parametrize(
"callback_error",
[
(ValueError("ValueError")),
(BaseException("BaseException")),
],
)
def test__wrap_callback_errors_error(callback_error):
msg = mock.create_autospec(message.Message, instance=True)
callback = mock.Mock(side_effect=callback_error)
on_callback_error = mock.Mock()
Expand Down