Match `maybe_open_crash_handler()` to non-maybe version

Such that it will deliver a `BoxedMaybeException` to the caller
regardless whether `pdb` is set, and proxy through all `**kwargs`.
py313_support
Tyler Goodlet 2025-03-03 18:53:13 -05:00
parent 6ca15c8b4d
commit 3d4aa22a79
1 changed files with 24 additions and 7 deletions

View File

@ -2287,6 +2287,13 @@ def _set_trace(
repl.set_trace(frame=caller_frame) repl.set_trace(frame=caller_frame)
# XXX TODO! XXX, ensure `pytest -s` doesn't just
# hang on this being called in a test.. XD
# -[ ] maybe something in our test suite or is there
# some way we can detect output capture is enabled
# from the process itself?
# |_ronny: ?
#
async def pause( async def pause(
*, *,
hide_tb: bool = True, hide_tb: bool = True,
@ -3194,6 +3201,15 @@ async def maybe_wait_for_debugger(
return False return False
class BoxedMaybeException(Struct):
'''
Box a maybe-exception for post-crash introspection usage
from the body of a `open_crash_handler()` scope.
'''
value: BaseException|None = None
# TODO: better naming and what additionals? # TODO: better naming and what additionals?
# - [ ] optional runtime plugging? # - [ ] optional runtime plugging?
# - [ ] detection for sync vs. async code? # - [ ] detection for sync vs. async code?
@ -3224,9 +3240,6 @@ def open_crash_handler(
''' '''
__tracebackhide__: bool = tb_hide __tracebackhide__: bool = tb_hide
class BoxedMaybeException(Struct):
value: BaseException|None = None
# TODO, yield a `outcome.Error`-like boxed type? # TODO, yield a `outcome.Error`-like boxed type?
# -[~] use `outcome.Value/Error` X-> frozen! # -[~] use `outcome.Value/Error` X-> frozen!
# -[x] write our own..? # -[x] write our own..?
@ -3268,6 +3281,8 @@ def open_crash_handler(
def maybe_open_crash_handler( def maybe_open_crash_handler(
pdb: bool = False, pdb: bool = False,
tb_hide: bool = True, tb_hide: bool = True,
**kwargs,
): ):
''' '''
Same as `open_crash_handler()` but with bool input flag Same as `open_crash_handler()` but with bool input flag
@ -3278,9 +3293,11 @@ def maybe_open_crash_handler(
''' '''
__tracebackhide__: bool = tb_hide __tracebackhide__: bool = tb_hide
rtctx = nullcontext rtctx = nullcontext(
enter_result=BoxedMaybeException()
)
if pdb: if pdb:
rtctx = open_crash_handler rtctx = open_crash_handler(**kwargs)
with rtctx(): with rtctx as boxed_maybe_exc:
yield yield boxed_maybe_exc