Skip to content

Restore plain text tracebacks and fix exit codes for code mode#9224

Merged
manzt merged 3 commits intomainfrom
manzt/plain-text-tracebacks
Apr 20, 2026
Merged

Restore plain text tracebacks and fix exit codes for code mode#9224
manzt merged 3 commits intomainfrom
manzt/plain-text-tracebacks

Conversation

@manzt
Copy link
Copy Markdown
Collaborator

@manzt manzt commented Apr 16, 2026

Fixes a regression from #8376 brought back HTML-wrapping for errors in code mode. Additionally, errors in child cells now also cause the done event to report success: false, so execute-code.sh callers get exit code 1. Finally, simplifies _print_summary to just report (error) in the for cells since it appears in the traceback already.

Fixes a regression from #8376 brought back HTML-wrapping for errors in
code mode. Additionally, errors in child cells now also cause the done
event to report `success: false`, so `execute-code.sh` callers get exit
code 1. Finally, simplifies `_print_summary` to just report `(error)` in
the for cells since it appears in the traceback already.
Copilot AI review requested due to automatic review settings April 16, 2026 15:31
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Apr 20, 2026 2:53pm

Request Review

Comment thread marimo/_server/scratchpad.py Outdated
exc_type = (
getattr(err, "exception_type", None) or type(err).__name__
)
short_id = str(msg.cell_id)[:8]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is always short? maybe could lead to a bug otherwise?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i changed to just the msg.cell_id, so the model gets the full context.

mscolnick
mscolnick previously approved these changes Apr 16, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes code-mode scratchpad error reporting regressions by ensuring tracebacks are plain text (not HTML-highlighted) in code mode and by propagating errors from child cells into the final “done” result so callers can rely on non-zero exit status.

Changes:

  • Track and surface errors from non-scratch “child” cells during scratchpad execution, causing the done event / extract_result to report success: false.
  • Restore plain-text traceback payloads in code mode (avoid HTML-wrapping/highlighting).
  • Simplify code-mode _print_summary to avoid duplicating error details that are already present in streamed tracebacks (only annotate with (error)).

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
marimo/_server/scratchpad.py Adds child-cell error tracking and uses it in build_done_event / extract_result.
marimo/_server/api/endpoints/execution.py Passes the scratchpad listener into build_done_event so child errors affect success.
marimo/_mcp/code_server/main.py Passes the listener into extract_result so MCP callers see failure on child errors.
marimo/_messaging/tracebacks.py Sends plain text traceback data in code mode, HTML-highlighted otherwise.
marimo/_code_mode/_context.py Updates summary output to append (error) and stops printing duplicated error blocks to stderr.
tests/_server/test_scratchpad.py Adds tests for child-error propagation into done/extract_result behavior.
tests/_code_mode/test_context.py Updates expectations so _print_summary no longer writes runtime errors to stderr.


# Add a blank line before the summary when cells errored,
# so the summary is visually separated from streamed tracebacks.
has_errors = _run and any(self._cell_errored(cid) for cid in _run)
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

has_errors = _run and any(...) can evaluate to the (possibly empty) set _run rather than a boolean, which is a bit error-prone and can confuse type checkers/readability. Consider making this explicitly boolean (e.g., has_errors = any(self._cell_errored(cid) for cid in _run)).

Suggested change
has_errors = _run and any(self._cell_errored(cid) for cid in _run)
has_errors = any(self._cell_errored(cid) for cid in _run)

Copilot uses AI. Check for mistakes.
Comment thread marimo/_server/scratchpad.py Outdated
Comment on lines +114 to +126
if (
msg.output is not None
and msg.output.channel == CellChannel.MARIMO_ERROR
and isinstance(msg.output.data, list)
and msg.output.data
):
err = msg.output.data[0]
exc_type = (
getattr(err, "exception_type", None) or type(err).__name__
)
short_id = str(msg.cell_id)[:8]
self.child_error_summaries.append(
f"cell '{short_id}' raised {exc_type}"
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new child_error_summaries population logic in on_notification_sent isn't exercised by tests: current tests only append to listener.child_error_summaries manually. Add a test that feeds a non-scratch CellNotification with output.channel == MARIMO_ERROR through on_notification_sent and asserts the summary is captured (and propagates into build_done_event/extract_result).

Copilot uses AI. Check for mistakes.
):
err = msg.output.data[0]
exc_type = (
getattr(err, "exception_type", None) or type(err).__name__
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is overlong and may fail formatting/linting checks (and hurts readability). Please wrap the exc_type = ... assignment across multiple lines (Black/Ruff-friendly).

Suggested change
getattr(err, "exception_type", None) or type(err).__name__
getattr(err, "exception_type", None)
or type(err).__name__

Copilot uses AI. Check for mistakes.
Truncating to 8 chars collapsed every cell in an embedded app to the
same label, since embedded cells share a 36-char UUID prefix
(`<uuid>Hbol`). The summary is a machine-readable SSE payload, not a
terminal line, so there's no width budget to save.
@manzt manzt added the bug Something isn't working label Apr 20, 2026
@manzt manzt enabled auto-merge (squash) April 20, 2026 15:08
@manzt manzt disabled auto-merge April 20, 2026 15:18
@manzt manzt merged commit 3def675 into main Apr 20, 2026
25 of 45 checks passed
@manzt manzt deleted the manzt/plain-text-tracebacks branch April 20, 2026 15:18
@github-actions
Copy link
Copy Markdown

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.2-dev58

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants