Skip to content

Remove redundant try/catch around xterm dimensions read#315058

Merged
bryanchen-d merged 3 commits intomainfrom
brchen/terminal-pty-dimensions-cleanup
May 7, 2026
Merged

Remove redundant try/catch around xterm dimensions read#315058
bryanchen-d merged 3 commits intomainfrom
brchen/terminal-pty-dimensions-cleanup

Conversation

@bryanchen-d
Copy link
Copy Markdown
Contributor

@bryanchen-d bryanchen-d commented May 7, 2026

What

Follow-up to #314795. Removes the defensive try/catch around the rawXterm.dimensions?.css.canvas.{width,height} read in TerminalInstance._updatePtyDimensions. The preceding isDisposed early-return — together with the matching guards added in #314795 on the resize closures and TerminalResizeDebouncer — already covers the dispose race that motivated the original PR (telemetry buckets aaa283a2, 4826565b, 1e83a096).

Why

The Disposable base flips this._store.isDisposed to true before disposing children, so any debounced/idle resize callback that fires after TerminalInstance.dispose() returns early at the top of _updatePtyDimensions and never reaches rawXterm.dimensions.

The point of removing the try/catch is to surface any non-dispose scenarios that could still cause rawXterm.dimensions to throw. With the try/catch in place, those would be silently swallowed and we'd have no signal that they exist. By letting them propagate, telemetry will tell us whether there are other code paths (e.g. renderer rebuild, GPU/canvas fallback, font reflow) that hit this getter in a bad state — at which point we can target them specifically rather than guessing.

Risk

  • No behavior change in the dispose paths covered by the existing isDisposed guard.
  • If a non-dispose race exists, a TypeError will surface in telemetry. Acceptable trade-off: we want that signal so we can address it at the source.

Refs #314795

Follow-up to #314795. The `isDisposed` early-return at the top of
`_updatePtyDimensions` (plus the matching guards on the resize closures
and `TerminalResizeDebouncer`) already covers all three telemetry
buckets that motivated #314795: `aaa283a2`, `4826565b`, `1e83a096`. The
disposable store flips `isDisposed` to true before disposing children,
so any debounced/idle callback that fires after
`TerminalInstance.dispose()` returns early before reaching
`rawXterm.dimensions`.

The try/catch was added defensively against a hypothetical future race
where xterm.js' `RenderService` is disposed independently of the
`TerminalInstance` lifecycle. That scenario is not represented in the
current telemetry, and swallowing the throw would suppress the signal
we'd need to diagnose it. Prefer to surface such failures via telemetry
and address them at the source — xterm.js' `Terminal.dimensions` is
typed `IRenderDimensions | undefined`, so the getter should honor that
contract rather than throw post-dispose.

Refs #314795
Copilot AI review requested due to automatic review settings May 7, 2026 17:32
@bryanchen-d bryanchen-d requested a review from anthonykim1 May 7, 2026 17:35
Copy link
Copy Markdown
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

This PR is a follow-up to #314795 that removes the now-redundant defensive try/catch around reading rawXterm.dimensions?.css.canvas.{width,height} in TerminalInstance._updatePtyDimensions. With the existing isDisposed early-return and the resize/dispose guards added previously, the known resize-after-dispose race paths should already bail out before reaching the xterm dimensions getter.

Changes:

  • Remove the try/catch that swallowed exceptions from rawXterm.dimensions reads.
  • Read pixel dimensions directly via optional chaining and pass them through as before.
Show a summary per file
File Description
src/vs/workbench/contrib/terminal/browser/terminalInstance.ts Simplifies _updatePtyDimensions by removing defensive exception swallowing for rawXterm.dimensions access.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

@bryanchen-d bryanchen-d enabled auto-merge May 7, 2026 17:48
@bryanchen-d bryanchen-d merged commit 7ed9bb8 into main May 7, 2026
26 checks passed
@bryanchen-d bryanchen-d deleted the brchen/terminal-pty-dimensions-cleanup branch May 7, 2026 19:47
@vs-code-engineering vs-code-engineering Bot added this to the 1.120.0 milestone May 7, 2026
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] Uncaught TypeError: Cannot read properties of undefined (reading 'dimensions')

3 participants