Skip to content

Conversation

@junhaoliao
Copy link
Contributor

@junhaoliao junhaoliao commented Jan 5, 2026

Fixes #285890 (related: microsoft/monaco-editor#4702 )

Description

This PR fixes unhandled CancellationError exceptions that occur when the WordHighlighter is disposed while a delayed operation is pending.

The Delayer.trigger() method returns a Promise that rejects with CancellationError when cancelled (e.g., during disposal). Without proper error handling, this causes unhandled promise rejection warnings.

Changes

Added .catch(onUnexpectedError) to all three runDelayer.trigger() calls in wordHighlighter.ts.

The onUnexpectedError function from vs/base/common/errors automatically filters out CancellationError, so only genuine unexpected errors are reported.

This follows the same pattern used in other editor contributions:

  • parameterHintsModel.ts
  • findWidget.ts
  • stickyScrollModelProvider.ts

How to test

  1. Clone https://github.com/y-scope/yscope-log-viewer.git
  2. Run npm ci then npm run dev
  3. Open the browser console - without this fix, you'll see:
    Uncaught (in promise) Canceled: Canceled
        CancellationError errors.js:91
        cancel async.js:251
        dispose async.js:260
        dispose lifecycle.js:24
        clear lifecycle.js:114
        dispose lifecycle.js:98
        dispose wordHighlighter.js:652
        dispose wordHighlighter.js:709
        dispose lifecycle.js:24
    
  4. Replace the monaco-editor assets in the project with the built assets from this PR
  5. Restart the dev server (npm run dev)
  6. Verify the CancellationError warning no longer appears in the browser console

@junhaoliao
Copy link
Contributor Author

Hello @Yoyokrazy, would you mind taking a look to see if the fixes are correct? Please let me know if I should modify anything.

Copy link
Collaborator

@Yoyokrazy Yoyokrazy left a comment

Choose a reason for hiding this comment

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

This looks great, thank you for the contribution!

@Yoyokrazy Yoyokrazy enabled auto-merge (squash) January 5, 2026 18:08
@vs-code-engineering vs-code-engineering bot added this to the December 2025 milestone Jan 5, 2026
@Yoyokrazy Yoyokrazy merged commit 6e00083 into microsoft:main Jan 5, 2026
17 checks passed
@junhaoliao junhaoliao deleted the wordhighlighter-cancellation-error branch January 5, 2026 20:03
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 CancellationError in WordHighlighter when disposed during pending delayed operation.

4 participants