From 037b5e0dc21123a7d4ae0ea48af25b452d2ade3e Mon Sep 17 00:00:00 2001 From: mertunsall Date: Sat, 30 Aug 2025 20:13:16 +0200 Subject: [PATCH] raise the original error instead of wrapping it --- bubus/models.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/bubus/models.py b/bubus/models.py index f0b9159..4079e49 100644 --- a/bubus/models.py +++ b/bubus/models.py @@ -506,9 +506,17 @@ async def event_results_filtered( if raise_if_any and error_results: failing_handler, failing_result = list(error_results.items())[0] # throw first error - raise Exception( - f'Event handler {failing_handler}({self}) returned an error -> {failing_result.error or cast(Any, failing_result.result)}' - ) + original_error = failing_result.error or cast(Any, failing_result.result) + + # Log the handler context information instead of wrapping the exception + logger.debug(f'Event handler {failing_handler}({self}) returned an error -> {original_error}') + + # Re-raise the original exception to preserve its type and structured data + if isinstance(original_error, BaseException): + raise original_error + else: + # Fallback for non-exception errors (shouldn't happen in practice) + raise Exception(str(original_error)) if raise_if_none and not included_results: raise ValueError(