Skip to content

Conversation

@SamarJyoti496
Copy link
Contributor

@SamarJyoti496 SamarJyoti496 commented Nov 3, 2025

📝 Summary

Syntax Errors now show red line highlighting in the editor matching the existing behavior for runtime errors.

Fixes #6979

🔍 Description of Changes

Problem: Syntax errors displayed error messages but didn't highlight the problematic line in red, unlike runtime errors.

Solution: Extract line numbers from Python's SyntaxError.lineno attribute and feed them into the existing traceback.

📋 Checklist


Note

Extracts lineno for Python syntax/import-star errors in the runtime, exposes it via API, and updates frontend traceback logic to highlight exact error lines, with comprehensive tests.

  • Backend:
    • Add optional lineno to MarimoSyntaxError and ImportStarError; capture from SyntaxError.lineno in runtime.
  • API:
    • Extend OpenAPI schema and generated TS (packages/openapi) to include lineno on MarimoSyntaxError and ImportStarError.
  • Frontend:
    • Refactor createTracebackInfoAtom to use cellRuntimeAtom and parse syntax/import-star errors with lineno into TracebackInfo (skip when queued/running).
    • Enhance mocks to allow per-cell cellRuntime overrides.
    • Export createTracebackInfoAtom for testing.
  • Tests:
    • Add/expand tests validating lineno propagation (including 0, null, multiline) and new traceback behavior; update serialization expectations to include lineno.

Written by Cursor Bugbot for commit 9da2233. This will update automatically on new commits. Configure here.

@vercel
Copy link

vercel bot commented Nov 3, 2025

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

Project Deployment Preview Comments Updated (UTC)
marimo-docs Ready Ready Preview Comment Nov 4, 2025 7:18pm

error = MarimoImportStarError(msg=str(e))
else:
error = MarimoSyntaxError(msg="\n".join(syntax_error))
error = MarimoSyntaxError(
Copy link
Contributor

Choose a reason for hiding this comment

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

if there are any tests that check the a MarimoSyntaxError was created, can you also check that lineno was also added

// so it prevents downstream recomputations.
const tracebackStringAtom = atom<string | undefined>((get) => {
// Single flat atom - proper reactivity
return atom((get: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

this now runs on every notebook change. can we instead at least do keep the intermediate atom that computes cellDataAtom (just returning const data = notebook.cellRuntime[cellId])

@mscolnick
Copy link
Contributor

@SamarJyoti496 you will also need to run make fe-codegen. this might create some newlines in areas that are unrealted. you can revert parts of that change as we look into why it does that

@github-actions github-actions bot added the bash-focus Area to focus on during release bug bash label Nov 4, 2025
@SamarJyoti496
Copy link
Contributor Author

@SamarJyoti496 you will also need to run make fe-codegen. this might create some newlines in areas that are unrealted. you can revert parts of that change as we look into why it does that

I have updated that one. Some backend test cases failed, but I'm not sure whether they're related to my changes. I think they're not as they had run successfully before.

mscolnick
mscolnick previously approved these changes Nov 4, 2025
Copy link
Contributor

@mscolnick mscolnick left a comment

Choose a reason for hiding this comment

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

looks great!

@mscolnick mscolnick requested a review from Copilot November 4, 2025 14:58
Copy link
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 adds line number tracking to syntax errors in Marimo. The changes enable syntax errors to capture and display the line number where the error occurred, improving debugging capabilities.

  • Added an optional lineno field to the MarimoSyntaxError class with a default value of None
  • Updated the runtime to extract and pass line numbers from Python SyntaxError exceptions
  • Enhanced the frontend to display syntax error line numbers in the traceback interface

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
marimo/_messaging/errors.py Added optional lineno field to MarimoSyntaxError struct
marimo/_runtime/runtime.py Extracts lineno from Python SyntaxError and passes it to MarimoSyntaxError
frontend/src/core/cells/cells.ts Refactored createTracebackInfoAtom to handle both runtime and syntax errors, adding traceback info for syntax errors with line numbers
packages/openapi/api.yaml Updated API schema to include optional lineno field for MarimoSyntaxError
packages/openapi/src/api.ts Generated TypeScript types reflecting the new lineno field
tests/_messaging/test_messaging_errors.py Added tests for MarimoSyntaxError with and without lineno
tests/_messaging/test_cell_output.py Updated expected serialization to include lineno: None field
tests/_runtime/test_runtime.py Added assertions to verify lineno is captured correctly in syntax errors

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 879 to 885
lineno = getattr(e, "lineno", None)
if isinstance(e, ImportStarError):
error = MarimoImportStarError(msg=str(e))
else:
error = MarimoSyntaxError(msg="\n".join(syntax_error))
error = MarimoSyntaxError(
msg="\n".join(syntax_error), lineno=lineno
)
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

The lineno is extracted from the exception but not passed to MarimoImportStarError. Since ImportStarError is a subclass of SyntaxError (as shown in marimo/_ast/errors.py), it should also include the line number information. Consider adding a lineno field to MarimoImportStarError or documenting why it's intentionally excluded.

Copilot uses AI. Check for mistakes.
const tracebackStringAtom = atom<string | undefined>((get) => {
const notebook = get(notebookAtom);
const data = notebook.cellRuntime[cellId];
//use existing cellRuntimeAtom for intermediate computation
Copy link

Copilot AI Nov 4, 2025

Choose a reason for hiding this comment

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

Corrected comment formatting: 'use' should be capitalized and there should be a space after '//'.

Suggested change
//use existing cellRuntimeAtom for intermediate computation
// Use existing cellRuntimeAtom for intermediate computation

Copilot uses AI. Check for mistakes.
@mscolnick
Copy link
Contributor

@SamarJyoti496 im going to push some changes for some tests and a bit of cleanup

cursor[bot]

This comment was marked as outdated.

@mscolnick mscolnick merged commit 345a419 into marimo-team:main Nov 4, 2025
38 of 60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bash-focus Area to focus on during release bug bash

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Highlight the syntax error in the cell

2 participants