Skip to content

Drop structure highlighting runs with a zero-width header - #1321

Merged
microbit-matt-hillsdon merged 1 commit into
mainfrom
structure-highlighting-error-node
Sep 10, 2026
Merged

Drop structure highlighting runs with a zero-width header#1321
microbit-matt-hillsdon merged 1 commit into
mainfrom
structure-highlighting-error-node

Conversation

@microbit-matt-hillsdon

Copy link
Copy Markdown
Collaborator

A document starting with a colon recovers as a compound statement whose header is a zero-length error node:

    ":\n    pass\n"      TryStatement children: ⚠(0,0) Body(0,11)
    "if a:\n    pass\n"  IfStatement children: if(0,2) VariableName(3,4) Body(4,15)

start and bodyStart are then both 0, so positionsForNode asked skipBodyTrailers for position -1 and doc.lineAt threw. That accounts for 4181 events in Sentry since April 2024, the largest single group in the project, and it is still present in v3.1.11.

Skip this shape as we cannot meaningfully render it.

Fixes #1318

A document starting with a colon recovers as a compound statement whose
header is a zero-length error node:

    ":\n    pass\n"      TryStatement children: ⚠(0,0) Body(0,11)
    "if a:\n    pass\n"  IfStatement children: if(0,2) VariableName(3,4) Body(4,15)

start and bodyStart are then both 0, so positionsForNode asked
skipBodyTrailers for position -1 and doc.lineAt threw. That accounts for
4181 events in Sentry since April 2024, the largest single group in the
project, and it is still present in v3.1.11.

Skip this shape as we cannot meaningfully render it.

Fixes #1318
@github-actions

Copy link
Copy Markdown

@microbit-matt-hillsdon

Copy link
Copy Markdown
Collaborator Author

So far as I can tell the only impact of this is the logged errors and stale structure highlighting. Worst case is pasting a repro over a doc with existing structure highlighting.

@microbit-grace microbit-grace 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.

Looks good

@microbit-matt-hillsdon
microbit-matt-hillsdon merged commit 3eab0e0 into main Sep 10, 2026
2 checks passed
@microbit-matt-hillsdon
microbit-matt-hillsdon deleted the structure-highlighting-error-node branch September 10, 2026 08:54
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.

[Code structure] skipBodyTrailers passed -1, throwing Invalid position

2 participants