Skip to content

fix: enrich notebook model index error diagnostics and fix sort comparator (#301207)#302298

Merged
bryanchen-d merged 2 commits intomainfrom
bryanchen-d/fix-notebook-index-out-of-range
Mar 17, 2026
Merged

fix: enrich notebook model index error diagnostics and fix sort comparator (#301207)#302298
bryanchen-d merged 2 commits intomainfrom
bryanchen-d/fix-notebook-index-out-of-range

Conversation

@bryanchen-d
Copy link
Contributor

@bryanchen-d bryanchen-d commented Mar 16, 2026

Fixes #301207

Problem

Unhandled error model index out of range 11 in NotebookTextModel._assertIndex provides no diagnostic context — no cell count, no edit type, no indication of which lookup key produced the invalid index — making it difficult to determine the root cause from telemetry alone.

Additionally, the sort comparator in _doApplyEdits returned -1 when b.end === undefined (DocumentMetadata edits), which incorrectly sorted them after cell-referencing edits instead of before them.

Changes

  1. Enrich _assertIndex error message — include cellCount and an optional context string so telemetry reports show the cell count and which edit type / lookup key triggered the failure.

  2. Pass context to _assertIndex in the handle-lookup branch — so handle-based lookups also report diagnostic details.

  3. Fix sort comparator — change return -1 to return 1 for the b.end === undefined case so DocumentMetadata edits (which have no cell index) sort before cell-referencing edits, matching the existing a.end === undefined branch.

Copilot AI review requested due to automatic review settings March 16, 2026 23:38
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

Fixes an unhandled “model index out of range” error in notebook edit application by adding more diagnostic context to index validation and correcting edit ordering during application in NotebookTextModel.

Changes:

  • Adds optional diagnostic context to _assertIndex error messages (including current cell count).
  • Validates index-based (non-Replace/non-Move) edits earlier during edit mapping, similar to handle-based validation.
  • Adjusts the edit sorting comparator for end === undefined (DocumentMetadata) edits.

@bryanchen-d bryanchen-d force-pushed the bryanchen-d/fix-notebook-index-out-of-range branch from 7650036 to 5940edb Compare March 16, 2026 23:45
@bryanchen-d bryanchen-d force-pushed the bryanchen-d/fix-notebook-index-out-of-range branch from 5940edb to 882573e Compare March 17, 2026 16:09
@bryanchen-d bryanchen-d force-pushed the bryanchen-d/fix-notebook-index-out-of-range branch from 882573e to e660fad Compare March 17, 2026 17:04
@bryanchen-d bryanchen-d marked this pull request as ready for review March 17, 2026 18:02
@bryanchen-d bryanchen-d enabled auto-merge March 17, 2026 18:02
@vs-code-engineering vs-code-engineering bot added this to the 1.113.0 milestone Mar 17, 2026
@bryanchen-d bryanchen-d merged commit 4922d2a into main Mar 17, 2026
20 checks passed
@bryanchen-d bryanchen-d deleted the bryanchen-d/fix-notebook-index-out-of-range branch March 17, 2026 18:47
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.

[Unhandled Error] Illegal argument

3 participants