Skip to content

feat: highlight the line a Python error points at - #1709

Merged
maxelkins merged 6 commits into
mainfrom
feature/python-error-line-highlight
Oct 23, 2026
Merged

maxelkins merged 6 commits into
mainfrom
feature/python-error-line-highlight

Conversation

@maxelkins

@maxelkins maxelkins commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Created with AI assistance
👨‍💻 Edited, reviewed and steered by @maxelkins

Summary

Highlight the line a Python error points to, create a visual connection between the error and the code.

Changes

  • Add a CodeMirror extension that highlights one line and its line number
  • Highlight the line from errorDetails when the error is in that .py file, clearing it on edit
  • Add per-theme error-line colours using design-system reds, with a color-mix fallback
  • Add unit tests for highlighting, clearing and moving the error line, and for the line and file Pyodide passes into errorDetails
  • Add Cypress tests for the highlight in both runtimes and for the light and dark theme colours
  • Keep the highlight cleared after an edit with a new errorLineDismissed flag in Redux
  • Make the error bar on the line number right-to-left aware
  • Added a logical properties fix to the gutter spacing, overriding code mirrors physical properties.

How this works

  • We were already storing the line on which the error occurred in errorDetails
  • EditorPanel reads the errorDetails, and if the errors file matches that tab, it sends the line number to the code mirror extension, which then adds the line decoration
  • The gutter is highlighted using a gutter marker using the same line number so they always match.
  • The extension also checks for edits to the code and clears the error when an edit is made. EditorPanel then sets errorLineDismissed in Redux so the highlight doesn't come back when the editor is rebuilt i.e. switching tabs.
  • The extension applies custom properties which are then themed in our internal styles

Limitations

  • If the error is not in the currently open file tab, the tab does not change, but the line is highlighted when you switch to that tab. This is intentional because I didn't want to make any bigger interaction changes.
  • Screen readers don't announce the highlight, but the error message still gives the line number in text. Any changes here would need to be a separate accessibility consideration.

A11y

Screenshot 2026-10-23 at 12 11 22

Screenshots

Screenshot 2026-10-23 at 10 29 23 Screenshot 2026-10-23 at 10 29 31 Screenshot 2026-10-23 at 10 33 41

Right to left reading:

image

@maxelkins

Copy link
Copy Markdown
Contributor Author

Out of scope here, but found while testing: with Skulpt, an unclosed bracket on the last line (e.g. import turtle then print("hi") is reported one line past the end of the file ("line 3" for a 2-line file). The highlight ignores out-of-range lines, so nothing is highlighted in that case. The wrong line number comes from Skulpt and affects the error message too, so it should be fixed as a separate issue rather than worked around here.

maxelkins and others added 4 commits October 23, 2026 11:59
Students can find the failing line without counting. The line and its line number get a translucent design-system red, so the text selection still shows through, plus a solid bar on the number.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Covers highlighting, clearing and moving in EditorPanel, the line and file Pyodide passes into errorDetails, and the highlight and theme colours end to end.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@maxelkins
maxelkins force-pushed the feature/python-error-line-highlight branch from 9dbadaf to b8e60bc Compare October 23, 2026 10:59
@maxelkins
maxelkins marked this pull request as ready for review October 23, 2026 11:00
Comment thread src/components/Editor/EditorPanel/EditorPanel.jsx Outdated

@zetter-rpf zetter-rpf left a comment

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.

Do you think there's any way to reduce the number of browser based tests?

While it's helpful to have unit tests that are specific, because browser based tests take longer to run and maintain I wondered if all of them are worth the cost.

Seeing the error highlighted is just one part of a set of behaviour around error messages - maybe they could be combined with each other or existing tests related to errors without losing coverage?

@zetter-rpf zetter-rpf left a comment

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 tried it out and it works great, what a great bonus feature for Friday!

Have a suggestion about tests, but I haven't looked at the existing error related tests so don't know how feasible it is.

@maxelkins

Copy link
Copy Markdown
Contributor Author

Thanks @zetter-rpf Will take a look at the feedback 👍

The full filename check already prevents errors from highlighting the wrong file. Removing the Python-only guard lets other runners use the same error details contract in future.
Fold the highlight checks into existing runner error scenarios and leave detailed behaviour to the component tests. This keeps end-to-end coverage for both runtimes without adding extra browser runs.
@maxelkins
maxelkins merged commit 88b1e92 into main Oct 23, 2026
12 checks passed
@maxelkins
maxelkins deleted the feature/python-error-line-highlight branch October 23, 2026 13:48

This branch was successfully deployed

1 active deployment
previews/1709/merge — 5df817ea Deployed Oct 23, 2026 by maxelkins via deploy-branch / build-deploy #6996
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants