Raise RTE from `limit_plds()` on no `curr_ctx`

Since it should only be used from within a `Portal.open_context()`
scope, make sure the caller knows that!

Also don't hide the frame in tb if the immediate function errors..
ext_type_plds
Tyler Goodlet 2025-03-08 15:50:14 -05:00
parent 9ec63f8187
commit 8fa23fcccd
1 changed files with 12 additions and 2 deletions

View File

@ -461,11 +461,16 @@ def limit_plds(
''' '''
__tracebackhide__: bool = True __tracebackhide__: bool = True
curr_ctx: Context|None = current_ipc_ctx()
if curr_ctx is None:
raise RuntimeError(
'No IPC `Context` is active !?\n'
'Did you open `limit_plds()` from outside '
'a `Portal.open_context()` scope-block?'
)
try: try:
curr_ctx: Context = current_ipc_ctx()
rx: PldRx = curr_ctx._pld_rx rx: PldRx = curr_ctx._pld_rx
orig_pldec: MsgDec = rx.pld_dec orig_pldec: MsgDec = rx.pld_dec
with rx.limit_plds( with rx.limit_plds(
spec=spec, spec=spec,
**dec_kwargs, **dec_kwargs,
@ -475,6 +480,11 @@ def limit_plds(
f'{pldec}\n' f'{pldec}\n'
) )
yield pldec yield pldec
except BaseException:
__tracebackhide__: bool = False
raise
finally: finally:
log.runtime( log.runtime(
'Reverted to previous payload-decoder\n\n' 'Reverted to previous payload-decoder\n\n'