Commit e0a9c76
Render exception snapshots with flattened chain + DAP overlay
Summary:
Special-case exception snapshots so VS Code's CALL STACK panel
stops labelling them as "Thread N" and instead presents the full
cause/context chain as a single inline narrative — the same shape
users already read from ``traceback.print_exception``.
Four DAP-level improvements, all pydevd-parity:
1. **Flattened exception-chain "thread".** When a snapshot carries
any exception stacktraces, ``handle_threads`` now replaces them
with a single synthetic ``Exception: <ExcType>(<msg>)`` row (id
``-1``). Requests for that id in ``handle_stack_trace`` walk the
``__cause__`` / ``__context__`` chain and return a merged frame
list that matches CPython's ``traceback.print_exception`` order
— innermost cause first, outermost (most-recently-raised)
last, with separator label rows between exception groups:
▸ origin() ← innermost cause frame (top)
▸ foo()
▸ ⬆ CAUSED BY ⬆ ← separator (non-navigable)
▸ raiser() ← outer exception frames
▸ main() ← original entry (bottom)
Reading the panel top-down flows: "original cause happened →
⬆ caused by ⬆ → outer exception was then raised below". The
up-arrows on the separator correctly point at the cause that
was just rendered above them. Within each exception group,
frames are innermost-first per DAP convention
(``frame[0]`` = active frame).
Separator frames use the DAP-standard
``presentationHint: "label"`` so VS Code renders them as dim
non-clickable headers. Implicit ``__context__`` chains use
``⬆ DURING HANDLING OF ⬆``. Chain walk is cycle-guarded and
bounded at ``_MAX_EXCEPTION_CHAIN_DEPTH = 10``, matching the cap
in :mod:`tintype.dap.exceptions`. Real (non-exception) threads
remain visible alongside the synthetic row.
2. **Innermost-cause-anchored exception surfaces.** Under the
flattened chain the top stack frame is the innermost cause's
innermost frame (where the original exception was raised). Two
separate DAP surfaces carry exception-description text; both
should describe the innermost exception so what the user sees
matches the frame they're looking at. We source both from the
innermost for the virtual chain thread:
* ``ExceptionInfoResponse`` (``exceptionId`` / ``description``
/ ``details.message``) drives the red "Exception has
occurred" decoration VS Code paints on the top frame's
source line, plus the hover tooltip and the Exception Info
panel. ``handle_exception_info(threadId=-1)`` routes to the
innermost; ``innerException`` is naturally empty there
(innermost has no further ``__cause__`` / ``__context__``).
Sourcing from the outer effect here would paint the cause's
raise site with the wrong exception's message — actively
misleading. The outer exception's info still reaches the
user via the flattened CALL STACK rows, which carry both
exceptions' frames.
* ``stopped.text`` is the secondary annotation VS Code shows
beside the stopped thread's row in the CALL STACK panel
(e.g. ``Paused on exception: TypeError: …``). Sourcing from
the innermost keeps the annotation consistent with the red
overlay — a user who sees "TypeError" on the offending line
shouldn't see "ValueError" on the CALL STACK row that
selected it. Output shape is ``<ExcType>: <message>``
(matching CPython's ``traceback`` format),
single-line-collapsed and capped at 512 chars so the
annotation stays readable.
Non-chain threads continue to source from the thread's own
exception. Non-exception snapshots leave both surfaces unset.
See ``_pick_exception_chain_innermost`` and
``_format_stopped_exception_text`` in
``tintype/dap/session.py``.
3. **``ExceptionDetails.innerException`` chain** — for non-chain
threads (and any future caller that passes a chain root
stacktrace), ``build_exception_info`` now emits a proper
nested ``innerException`` array so clients that render the
tree (VS Code included) can expand each chained exception
independently. ``stackTrace`` (the pre-rendered text) remains
for clients that ignore ``innerException``. See
``_build_details`` in ``tintype/dap/exceptions.py``.
4. **``StackFrame.presentationHint: "subtle"``** — per the DAP
spec, frame hints are ``normal | label | subtle``; pydevd uses
``"subtle"`` for framework-noise frames. ``"deemphasize"`` is
only a valid value for ``Source.presentationHint``. Aligning
with the spec and pydevd.
Also updates ``_pick_stop_thread`` to prefer the virtual chain
thread for exception snapshots (instead of a specific exception
stacktrace id) so the initial stop focuses the synthetic row.
Reviewed By: aperez
Differential Revision: D103567305
fbshipit-source-id: 2c3cb0b929f0d318e4a49821fe015560a3ca89bc1 parent c691315 commit e0a9c76
3 files changed
Lines changed: 961 additions & 36 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
49 | 64 | | |
50 | 65 | | |
51 | 66 | | |
52 | 67 | | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
60 | 73 | | |
| 74 | + | |
| 75 | + | |
61 | 76 | | |
62 | 77 | | |
63 | 78 | | |
| |||
66 | 81 | | |
67 | 82 | | |
68 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
69 | 133 | | |
70 | 134 | | |
71 | 135 | | |
| |||
0 commit comments