Drop `except*` usage from `._taskc` unmasker
That is from `maybe_raise_from_masking_exc()` thus minimizing us to a single `except BaseException` block with logic branching for the beg vs. `unmask_from` exc cases. Also, - raise val-err when `unmask_from` is not a `tuple`. - tweak the exc-note warning format. - drop all pausing from dev work.to_asyncio_eoc_signal
parent
72c4a9d20b
commit
02062c5dc0
|
@ -74,8 +74,9 @@ async def maybe_raise_from_masking_exc(
|
||||||
raise_unmasked: bool = True,
|
raise_unmasked: bool = True,
|
||||||
extra_note: str = (
|
extra_note: str = (
|
||||||
'This can occurr when,\n'
|
'This can occurr when,\n'
|
||||||
' - a `trio.Nursery` scope embeds a `finally:`-block '
|
'\n'
|
||||||
'which executes a checkpoint!'
|
' - a `trio.Nursery/CancelScope` embeds a `finally/except:`-block '
|
||||||
|
'which execs an un-shielded checkpoint!'
|
||||||
#
|
#
|
||||||
# ^TODO? other cases?
|
# ^TODO? other cases?
|
||||||
),
|
),
|
||||||
|
@ -104,62 +105,52 @@ async def maybe_raise_from_masking_exc(
|
||||||
individual sub-excs but maintain the eg-parent's form right?
|
individual sub-excs but maintain the eg-parent's form right?
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
if not isinstance(unmask_from, tuple):
|
||||||
|
raise ValueError(
|
||||||
|
f'Invalid unmask_from = {unmask_from!r}\n'
|
||||||
|
f'Must be a `tuple[Type[BaseException]]`.\n'
|
||||||
|
)
|
||||||
|
|
||||||
from tractor.devx.debug import (
|
from tractor.devx.debug import (
|
||||||
BoxedMaybeException,
|
BoxedMaybeException,
|
||||||
pause,
|
|
||||||
)
|
)
|
||||||
boxed_maybe_exc = BoxedMaybeException(
|
boxed_maybe_exc = BoxedMaybeException(
|
||||||
raise_on_exit=raise_unmasked,
|
raise_on_exit=raise_unmasked,
|
||||||
)
|
)
|
||||||
matching: list[BaseException]|None = None
|
matching: list[BaseException]|None = None
|
||||||
maybe_eg: ExceptionGroup|None
|
try:
|
||||||
|
yield boxed_maybe_exc
|
||||||
if tn:
|
return
|
||||||
try: # handle egs
|
except BaseException as _bexc:
|
||||||
yield boxed_maybe_exc
|
bexc = _bexc
|
||||||
return
|
if isinstance(bexc, BaseExceptionGroup):
|
||||||
except* unmask_from as _maybe_eg:
|
|
||||||
maybe_eg = _maybe_eg
|
|
||||||
matches: ExceptionGroup
|
matches: ExceptionGroup
|
||||||
matches, _ = maybe_eg.split(
|
matches, _ = bexc.split(unmask_from)
|
||||||
unmask_from
|
if matches:
|
||||||
)
|
matching = matches.exceptions
|
||||||
if not matches:
|
|
||||||
raise
|
|
||||||
|
|
||||||
matching: list[BaseException] = matches.exceptions
|
elif (
|
||||||
else:
|
unmask_from
|
||||||
try: # handle non-egs
|
and
|
||||||
yield boxed_maybe_exc
|
type(bexc) in unmask_from
|
||||||
return
|
):
|
||||||
except unmask_from as _maybe_exc:
|
matching = [bexc]
|
||||||
maybe_exc = _maybe_exc
|
|
||||||
matching: list[BaseException] = [
|
|
||||||
maybe_exc
|
|
||||||
]
|
|
||||||
|
|
||||||
# XXX, only unmask-ed for debuggin!
|
|
||||||
# TODO, remove eventually..
|
|
||||||
except BaseException as _berr:
|
|
||||||
berr = _berr
|
|
||||||
await pause(shield=True)
|
|
||||||
raise berr
|
|
||||||
|
|
||||||
if matching is None:
|
if matching is None:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
masked: list[tuple[BaseException, BaseException]] = []
|
masked: list[tuple[BaseException, BaseException]] = []
|
||||||
for exc_match in matching:
|
for exc_match in matching:
|
||||||
|
|
||||||
if exc_ctx := find_masked_excs(
|
if exc_ctx := find_masked_excs(
|
||||||
maybe_masker=exc_match,
|
maybe_masker=exc_match,
|
||||||
unmask_from={unmask_from},
|
unmask_from=set(unmask_from),
|
||||||
):
|
):
|
||||||
masked.append((exc_ctx, exc_match))
|
masked.append((exc_ctx, exc_match))
|
||||||
boxed_maybe_exc.value = exc_match
|
boxed_maybe_exc.value = exc_match
|
||||||
note: str = (
|
note: str = (
|
||||||
f'\n'
|
f'\n'
|
||||||
f'^^WARNING^^ the above {exc_ctx!r} was masked by a {unmask_from!r}\n'
|
f'^^WARNING^^\n'
|
||||||
|
f'the above {type(exc_ctx)!r} was masked by a {type(exc_match)!r}\n'
|
||||||
)
|
)
|
||||||
if extra_note:
|
if extra_note:
|
||||||
note += (
|
note += (
|
||||||
|
@ -171,14 +162,13 @@ async def maybe_raise_from_masking_exc(
|
||||||
if type(exc_match) in always_warn_on:
|
if type(exc_match) in always_warn_on:
|
||||||
log.warning(note)
|
log.warning(note)
|
||||||
|
|
||||||
# await tractor.pause(shield=True)
|
|
||||||
if raise_unmasked:
|
if raise_unmasked:
|
||||||
|
|
||||||
if len(masked) < 2:
|
if len(masked) < 2:
|
||||||
raise exc_ctx from exc_match
|
raise exc_ctx from exc_match
|
||||||
else:
|
# else:
|
||||||
# ?TODO, see above but, possibly unmasking sub-exc
|
# # ?TODO, see above but, possibly unmasking sub-exc
|
||||||
# entries if there are > 1
|
# # entries if there are > 1
|
||||||
await pause(shield=True)
|
# await pause(shield=True)
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
|
|
Loading…
Reference in New Issue