From f86f4ae48d0268817c6ba77423998d363f9dce3e Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Mon, 7 Jul 2025 10:02:27 -0400 Subject: [PATCH] Facepalm, fix `raise from` in `collapse_eg()` I dunno what exactly I was thinking but we definitely don't want to **ever** raise from the original exc-group, instead always raise from any original `.__cause__` to be consistent with the embedded src-error's context. Also, adjust `maybe_collapse_eg()` to return `False` in the non-single `.exceptions` case, again don't know what I was trying to do but this simplifies caller logic and the prior return-semantic had no real value.. This fixes some final usage in the runtime (namely top level nursery usage in `._root`/`._runtime`) which was previously causing test suite failures prior to this fix. --- tractor/trionics/_beg.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tractor/trionics/_beg.py b/tractor/trionics/_beg.py index 2407fca7..4204df19 100644 --- a/tractor/trionics/_beg.py +++ b/tractor/trionics/_beg.py @@ -31,7 +31,7 @@ import trio def maybe_collapse_eg( beg: BaseExceptionGroup, -) -> BaseException: +) -> BaseException|bool: ''' If the input beg can collapse to a single non-eg sub-exception, return it instead. @@ -40,13 +40,12 @@ def maybe_collapse_eg( if len(excs := beg.exceptions) == 1: return excs[0] - return beg + return False @acm async def collapse_eg( hide_tb: bool = True, - raise_from_src: bool = False, ): ''' If `BaseExceptionGroup` raised in the body scope is @@ -61,9 +60,11 @@ async def collapse_eg( except* BaseException as beg: if ( exc := maybe_collapse_eg(beg) - ) is not beg: - from_exc = beg if raise_from_src else None - raise exc from from_exc + ): + if cause := exc.__cause__: + raise exc from cause + + raise exc raise beg