Remove redundant try/catch around xterm dimensions read#315058
Merged
bryanchen-d merged 3 commits intomainfrom May 7, 2026
Merged
Remove redundant try/catch around xterm dimensions read#315058bryanchen-d merged 3 commits intomainfrom
bryanchen-d merged 3 commits intomainfrom
Conversation
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
anthonykim1
approved these changes
May 7, 2026
Contributor
There was a problem hiding this comment.
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/catchthat swallowed exceptions fromrawXterm.dimensionsreads. - 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Follow-up to #314795. Removes the defensive
try/catcharound therawXterm.dimensions?.css.canvas.{width,height}read inTerminalInstance._updatePtyDimensions. The precedingisDisposedearly-return — together with the matching guards added in #314795 on the resize closures andTerminalResizeDebouncer— already covers the dispose race that motivated the original PR (telemetry bucketsaaa283a2,4826565b,1e83a096).Why
The
Disposablebase flipsthis._store.isDisposedtotruebefore disposing children, so any debounced/idle resize callback that fires afterTerminalInstance.dispose()returns early at the top of_updatePtyDimensionsand never reachesrawXterm.dimensions.The point of removing the
try/catchis to surface any non-dispose scenarios that could still causerawXterm.dimensionsto throw. With thetry/catchin 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
isDisposedguard.TypeErrorwill surface in telemetry. Acceptable trade-off: we want that signal so we can address it at the source.Refs #314795