fix: pretty format hidden variable behavior in stack traces#9660
Open
dmadisetti wants to merge 6 commits into
Open
fix: pretty format hidden variable behavior in stack traces#9660dmadisetti wants to merge 6 commits into
dmadisetti wants to merge 6 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
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
Contributor
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
Collaborator
Author
|
Created #9671 for flaky tests |
85188fe to
a934dbc
Compare
…ing/test_variables.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 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