fix: pretty format hidden variable behavior in stack traces#9660
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
1 issue found across 8 files
Architecture diagram
sequenceDiagram
participant User
participant UI as Frontend UI
participant Traceback as Traceback/Traceback Renderer
participant MarimoError as MarimoErrorOutput
participant MangledChip as MangledLocalChip
participant LocalVars as local-variables Utils
participant Runtime as Python Runtime
participant Variables as _ast/variables
participant Pytest as _runtime/pytest
Note over User,Pytest: Error display flow for mangled cell-local variables
User->>UI: Interacts with notebook cell
UI->>Runtime: Execute cell code
Runtime->>Variables: Compile cell (rewrites `_a` → `_cell_Hbol_a`)
Runtime-->>UI: Returns error with mangled name (e.g., `name '_cell_Hbol_a' is not defined`)
alt Standard output/message
UI->>MarimoError: Render NameError message
MarimoError->>LocalVars: splitMangledLocals(msg)
LocalVars-->>MarimoError: Segments [text, {cellId, name}, text]
MarimoError->>MangledChip: renderMangledSegments(segments)
MangledChip->>MangledChip: Render variable name + tooltip
MangledChip-->>MarimoError: React elements
MarimoError-->>UI: Display demangled variable with link
end
alt Traceback display
UI->>Traceback: Render full traceback
Traceback->>LocalVars: replaceMangledLocal(domNode)
LocalVars->>LocalVars: containsMangledLocal(text)
alt Has mangled name
LocalVars->>LocalVars: splitMangledLocals(text)
LocalVars-->>Traceback: Segments
Traceback->>MangledChip: renderMangledSegments(segments)
MangledChip-->>Traceback: React elements
else No mangled name
LocalVars-->>Traceback: Return unchanged
end
Traceback-->>UI: Display demangled traceback
end
alt Pytest output
Runtime->>Pytest: Run tests, capture report
Pytest->>Variables: demangle_locals_in_text(lines)
Variables-->>Pytest: Demangled exception/source lines
Pytest->>Variables: demangle_locals_in_text(reprcrash.message)
Variables-->>Pytest: Demangled summary message
Pytest-->>Runtime: Rewritten longrepr
Runtime-->>UI: Display demangled test output
end
Note over User,UI: User sees friendly variable name (e.g., `_a`) with tooltip showing defining cell
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
Pull request overview
This PR improves the readability of stack traces and error output by converting compiler-mangled “cell-local” variable names (e.g. _cell_<id>_a) back into the user-facing underscore-prefixed names (e.g. _a) in both backend pytest output and the frontend error/traceback UI.
Changes:
- Added a Python demangling helper (
demangle_locals_in_text) and applied it to pytestlongreprformatting. - Added a frontend utility to detect/split mangled locals and render them as user-friendly chips linking to the defining cell.
- Added unit tests on both Python and frontend sides to cover basic demangling/splitting behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/_ast/test_variables.py | Adds Python unit tests for demangling mangled locals in free-form text. |
| marimo/_runtime/pytest.py | Rewrites pytest longrepr traceback output to use marimo URIs and demangle locals. |
| marimo/_ast/variables.py | Introduces demangle_locals_in_text() via a compiled regex. |
| frontend/src/utils/local-variables.ts | Adds frontend parsing helpers to detect/split mangled locals for display. |
| frontend/src/utils/tests/local-variables.test.ts | Adds vitest coverage for frontend mangled-local parsing/splitting. |
| frontend/src/components/editor/output/MarimoTracebackOutput.tsx | Demangles mangled locals inside traceback HTML and the header message. |
| frontend/src/components/editor/output/MarimoErrorOutput.tsx | Demangles NameError messages for underscore-prefixed locals in the error UI. |
| frontend/src/components/editor/errors/mangled-local-chip.tsx | Adds UI rendering for mangled locals as chips with tooltips and cell links. |
6c67e17 to
ab58036
Compare
|
Created #9671 for flaky tests |
85188fe to
a934dbc
Compare
…ing/test_variables.py
|
Good suggestion @kirangadhave ! |
|
🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.9-dev6 |
📝 Summary
This PR renames "hidden" variables like
_a(saved in globals as_cell_<id>_<variable>) in stack traces to the expected variable name.closes #9623