Skip to content

fix(core): don't warn when tree-sitter highlight fails during client destroy - #1318

Open
HARIOM-JHA01 wants to merge 1 commit into
anomalyco:mainfrom
HARIOM-JHA01:fix/treesitter-destroy-warn
Open

fix(core): don't warn when tree-sitter highlight fails during client destroy#1318
HARIOM-JHA01 wants to merge 1 commit into
anomalyco:mainfrom
HARIOM-JHA01:fix/treesitter-destroy-warn

Conversation

@HARIOM-JHA01

@HARIOM-JHA01 HARIOM-JHA01 commented Aug 2, 2026

Copy link
Copy Markdown

Fixes #1319

Problem

When @opentui/core is torn down, TreeSitterClient.destroy() rejects any in-flight highlightOnce() promises with a generic Error("TreeSitter client destroyed"). CodeRenderable.startHighlight() treats every rejection as a real failure and logs a misleading warning:

Code highlighting failed, falling back to plain text: Error: ...

This races with client teardown on exit, so opencode users see the warning unexpectedly on shutdown even though nothing is actually broken.

Reported in anomalyco/opencode#36454.

Fix

  • client.ts: introduce a typed TreeSitterClientDestroyedError and reject pending requests (and pending initialization) with it in destroy().
  • Code.ts: silently bail out when highlighting fails due to client destroy (or the renderable is already destroyed), preserving warnings for genuine worker failures.
  • Testing: mock-tree-sitter-client supports rejectHighlightOnce; client destroy tests now assert TreeSitterClientDestroyedError;
  • Code renderer tests verify no console.warn on destroy-triggered failures while a real Error still warns.

Tests

  • bun test packages/core/src/lib/tree-sitter/client.test.ts (49 pass)
  • oxlint / oxfmt clean
  • Renderer tests (Code.test.ts) require the native lib and run in CI.

…destroy

The TreeSitterClient used a generic Error for teardown rejections, so CodeRenderable treated an expected destroy() during shutdown as a real failure and logged 'Code highlighting failed, falling back to plain text'. Introduce TreeSitterClientDestroyedError and skip the warning (and pointless fallback render) when highlighting fails because the client was destroyed, while preserving warnings for genuine worker failures.
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 highlighting failed, falling back to plain text warning logged on exit (destroy race)

1 participant