Skip to content

Preserve window.onerror details, fix ResizeObserver loop guard, and defer Tooltip resize updates - #23228

Merged
sergiou87 merged 8 commits into
developmentfrom
unknown-unknown-error
Nov 28, 2026
Merged

sergiou87 merged 8 commits into
developmentfrom
unknown-unknown-error

Conversation

@sergiou87

Copy link
Copy Markdown
Member

Agent assessment

Self-reported assessment, not an independent review.

Assessed revision: bd7d9244b3ef408eedabd49f2cfe7d24312063be

Dimension Assessment Rationale
Change confidence 9/10 ↑ All 35 targeted unit and UI tests (including real source-map lookup, non-Error formatting, multiline header sanitization, once-per-session ResizeObserver handling, and Tooltip rAF deferral/cleanup), npm run lint, tsc --noEmit, and a 5-bundle production webpack build passed at bd7d9244b3.
↑ Author manually verified ResizeObserver loop suppression and null-error reporting in a running build.
↓ Full npm test had 4 pre-existing local Git failures (push-test.ts x3, rev-parse-test.ts x1); CI checks have not run yet; deferring Tooltip resize updates trades a 1-frame positioning delay when already-visible tooltip content changes size.
Diagnosis confidence 9.5/10 ↑ Verified in Electron 44 that window.onerror receives error === null for ResizeObserver loop completed with undelivered notifications. and Electron's lib/renderer/init.ts forwards only error to uncaughtException, bypassing the existing guard.
↑ Confirmed withSourceMappedStack turns null and non-Error values without name/message into [Unknown]: [Unknown] and Tooltip was the only synchronous ResizeObserver setState caller.
Evidence fit 7/10 ↑ Matches production [Unknown]: [Unknown] renderer crash signatures (no stack, no non-fatal kind, zero resizeObserverLoopCompleted reports) and reproduces the same null-error path previously seen in #20760 and #21311.
↓ Existing [Unknown]: [Unknown] reports contain no stack or error message, so post-release telemetry is needed to confirm whether ResizeObserver loops account for all of the spike versus another null/non-Error source that this change will now unmask.

No tracking GitHub issue; addresses production [Unknown]: [Unknown] renderer crashes with missing stack traces.

Description

Production crash telemetry showed a spike in [Unknown]: [Unknown] renderer crashes with no stack trace. Tracing the renderer uncaught-exception pipeline uncovered three related gaps:

  1. Electron's window.onerror bridge drops error details when error is null: Electron's default renderer window.onerror handler forwards only its 5th error argument to process.emit('uncaughtException', error), discarding message, source, lineno, and colno. When Chromium emits ResizeObserver loop completed with undelivered notifications., error is null, so Desktop's existing ResizeObserver guard in app/src/ui/index.tsx never matched and crashed the app instead of treating the notification as non-fatal.
  2. withSourceMappedStack collapsed non-Error values to [Unknown]: [Unknown]: Any thrown null, undefined, primitive, function, DOM Event, or plain object without name/message properties lost all diagnostic detail and its stack.
  3. Tooltip called setState synchronously inside ResizeObserver: Unlike every other ResizeObserver consumer in the UI (Dialog, RichText, List, SectionList, ExpandableCommitSummary), Tooltip updated state synchronously inside its ResizeObserver callback.

Changes

  • Diagnostic non-Error formatting (app/src/lib/source-map-support.ts):
    • Update withSourceMappedStack to report null, undefined, primitives (safely formatted with String(...)), and functions under NonError, DOM Event objects with their constructor name and type, and other non-Error objects with their constructor name and sorted own property keys only (omitting values to avoid leaking sensitive data).
    • Preserve string stack properties on cross-realm/Error-like objects and guard property/function-name reads and JSON.stringify against throwing getters, null-prototype objects, and circular references.
    • Export mapSourceLocation to resolve 1-based bundle line/column positions through source maps.
  • Renderer window.onerror bridge and ResizeObserver handling (app/src/ui/lib/uncaught-exception.ts, app/src/ui/index.tsx):
    • Replace Electron's renderer window.onerror bridge via installWindowErrorHandler while preserving listenerCount('uncaughtException') return semantics. Real Error instances pass through unchanged; null, undefined, and non-Error values preserve message and a source-mapped source:line:col frame when lineno > 0.
    • Sanitize line breaks and at-prefixed names in synthetic stack headers so message text cannot be parsed as synthetic stack frames.
    • Extract createRendererUncaughtExceptionHandler to match Chromium ResizeObserver loop notifications (isResizeObserverLoopError), report resizeObserverLoopCompleted at most once per renderer session (avoiding starvation of the shared 1-per-minute sendNonFatalException rate limit), and keep the uncaughtException listener attached until an actual fatal error occurs.
  • Deferred Tooltip resize handling (app/src/ui/lib/tooltip.tsx):
    • Defer ResizeObserver re-measurement and setState updates to requestAnimationFrame with per-frame coalescing, cancelling pending frames when the tooltip detaches or unmounts and disconnecting the observer and hide timer on unmount.
    • Tradeoff: If an already-visible tooltip changes content size, its repositioned transform applies on the next animation frame rather than synchronously before paint (initial display is unaffected because onTooltipRef measures synchronously).

Validation

Covered at commit bd7d9244b3ef408eedabd49f2cfe7d24312063be (macOS arm64, Node v24.22.1):

  • npm test -- app/test/unit/source-map-support-test.ts app/test/unit/ui/uncaught-exception-test.ts app/test/unit/ui/tooltip-test.tsx app/test/unit/ui/issues-autocompletion-provider-test.tsx — passed (35/35 tests, covering real renderer.js + renderer.js.map source-map lookup, non-Error formatting, multiline stack-header sanitization, once-per-session ResizeObserver handling, and Tooltip rAF deferral/hide/unmount cleanup).
  • npm run lint (Prettier + ESLint) — passed.
  • npx tsc --noEmit — passed.
  • NODE_ENV=production TS_NODE_PROJECT=script/tsconfig.json NODE_OPTIONS='--max_old_space_size=8192' npx webpack --config app/webpack.production.ts — passed (all 5 production bundles compiled; note default 4096 MB heap hits the existing OOM tracked in Raise production webpack heap limit to 8 GiB #23224).
  • npm test — 3,633 passed, 2 skipped, 4 failed (the 4 failures are pre-existing local Git environment failures unrelated to this PR: 3 in app/test/unit/git/push-test.ts and 1 in app/test/unit/git/rev-parse-test.ts).
  • Manual testing by author confirmed ResizeObserver loop notifications no longer crash the app and null errors preserve their message and location instead of [Unknown]: [Unknown].

Screenshots

N/A — non-visual crash handling and internal Tooltip resize scheduling changes.

Release notes

Notes: [Fixed] Prevent unnecessary crashes from ResizeObserver loop notifications and improve unknown crash diagnostics

Team-authored review

Evidence: See the Validation section in Description (covering commit bd7d9244b3ef408eedabd49f2cfe7d24312063be) and the author's manual verification. No visual artifact: changes affect error normalization, renderer error routing, and Tooltip resize scheduling rather than visual UI.

Review path: Lightweight review. Author has assessed the changes and evidence; no changes to authentication, credentials, permissions, trust boundaries, destructive operations, release signing, or update mechanisms.

…tack

Previously, `withSourceMappedStack` replaced both `name` and `message`
with `[Unknown]` and dropped `stack` whenever it received a value that
was not a string and lacked `name`/`message` properties (such as `null`,
`undefined`, primitives, DOM `Event`s, or plain objects). As a result,
unrelated renderer crashes collapsed into a single `[Unknown]: [Unknown]`
Sentry issue (`DESKTOP-2T5`) with no actionable context.

Update `withSourceMappedStack` to:
- Report `null`, `undefined`, primitives (using `String(...)` so symbols
  cannot throw), and functions under `NonError` with their type/value.
- Report DOM `Event` objects using their constructor name and event
  `type`, and other non-Error objects using their constructor name and
  sorted own property names only (omitting values to avoid leaking
  sensitive data).
- Preserve string `stack` properties on cross-realm or plain Error-like
  objects where `error instanceof Error` is false.
- Guard property access and `JSON.stringify` against throwing getters,
  null-prototype objects, and circular references so crash reporting
  cannot throw recursively.

Add unit tests covering standard errors, cross-realm Error-like objects,
strings, null/undefined, primitives, functions, DOM events, plain and
null-prototype objects, circular `message` values, and throwing getters.
Electron's default renderer `window.onerror` bridge forwards only the
5th argument (`error`) to `process.emit('uncaughtException', error)`,
discarding `message`, `source`, `lineno`, and `colno`. When Chromium
reports `ResizeObserver loop completed with undelivered notifications.`,
`window.onerror` receives `error === null`, so Electron emitted
`uncaughtException(null)`. Desktop's `onUncaughtException` guard for
ResizeObserver loop notifications never matched `null`, causing a fatal
crash reported to Sentry as `[Unknown]: [Unknown]` (`DESKTOP-2T5`) and
leaving `resizeObserverLoopCompleted` non-fatal reporting with zero
events.

Introduce `app/src/ui/lib/uncaught-exception.ts` and wire it in
`app/src/ui/index.tsx`:
- Add `mapSourceLocation` to `app/src/lib/source-map-support.ts` to
  resolve 1-based bundle `lineno`/`colno` pairs through source maps.
- Add `normalizeWindowError` and `installWindowErrorHandler` to replace
  Electron's `window.onerror` handler in the renderer while preserving
  its `listenerCount('uncaughtException')` return semantics. Real
  `Error` instances are forwarded untouched; when `error` is `null`,
  `undefined`, or a non-Error value, the window error message and
  source-mapped `source:line:col` location (when `lineno > 0`) are
  preserved on a synthetic `Error` without capturing a misleading
  `window.onerror` stack trace.
- Add `isResizeObserverLoopError` so `onUncaughtException` matches both
  known Chromium ResizeObserver loop notifications and routes them to
  `sendNonFatalException('resizeObserverLoopCompleted', ...)` instead of
  crashing the application.

Add unit tests covering `isResizeObserverLoopError`,
`normalizeWindowError`, and `installWindowErrorHandler`.
`Tooltip` was the only `ResizeObserver` consumer in the UI still calling
`this.setState(...)` synchronously inside its `ResizeObserver` callback.
Repositioning a tooltip synchronously during resize observation (for
example, when placement near a viewport edge causes text wrapping or
box size changes) can trigger Chromium's `ResizeObserver loop completed
with undelivered notifications.` error.

Defer tooltip and target re-measurement and `setState` updates to
`requestAnimationFrame`, coalescing multiple resize notifications per
frame to match the rest of the codebase (`Dialog`, `RichText`, `List`,
`SectionList`, and `ExpandableCommitSummary`). Cancel pending resize
animation frames when the tooltip element detaches, and cancel timers,
pending animation frames, and `resizeObserver` on unmount.

Add UI component tests verifying that `Tooltip` defers layout updates
until the next animation frame, coalesces repeated resize notifications,
and cancels pending frames and disconnects its observer on unmount.
Reading `error.name.length` directly when normalizing a thrown function
would throw if the function defines a throwing `name` getter or a
non-string `name` value, aborting `normalizeWindowError` and crash
reporting before the exception reaches Desktop's handler.

Read the `name` property through `safeReadProperty` and verify it is a
non-empty string before formatting it, falling back to
`anonymous function`. Add unit tests covering both throwing `name`
getters and non-string `name` values on thrown functions.
Central's `JsException` parser scans every line of `stack` matching
`/^\s*at\s(.+?)$/` without sanitizing stack frames the way it sanitizes
`message`. If a thrown non-Error string or object contained a newline
followed by an `at ...` line (or an `at`-prefixed `name`),
`formatWindowErrorStack` embedded it verbatim into the synthetic stack
header, allowing message text (including local user paths) to be parsed
as unsanitized Sentry stack frames.

Collapse line breaks in the synthetic stack header and guard against
`at`-prefixed names so only the genuine mapped source location appears
on an `at ` line. Add regression tests for multiline strings and
`at`-prefixed names.
…ssion

`sendNonFatalException` enforces a single shared 1-per-minute throttle
across all `ExceptionKinds`. Because Chromium can emit
`ResizeObserver loop completed with undelivered notifications.` on every
animation frame while a loop persists, reporting every matched loop
notification would repeatedly consume the shared non-fatal slot and drop
unrelated non-fatal telemetry (`unhandledRejection`,
`copilotConflictResolution`, etc.).

Extract `createRendererUncaughtExceptionHandler` in
`app/src/ui/lib/uncaught-exception.ts` and wire it in `app/src/ui/index.tsx`
so `resizeObserverLoopCompleted` is reported at most once per renderer
session while still suppressing subsequent loop notifications without
detaching the `uncaughtException` listener. Add a regression test
covering once-per-session reporting, listener retention across ignored
ResizeObserver loops, and listener detachment after a fatal error.
Cover two gaps identified during review:
- Exercise `mapSourceLocation` directly against both unmapped files
  (preserving 1-based line/column and omitting 0/undefined columns) and
  a real `renderer.js` + `renderer.js.map` pair via `enableSourceMaps()`
  to verify 1-based to 0-based column conversion end-to-end.
- Exercise `Tooltip.onTooltipRef(null)` by hiding a visible tooltip on
  `mouseleave` while a resize `requestAnimationFrame` is pending,
  confirming the pending frame is cancelled and the observer is
  disconnected.
Copilot AI balanced review requested due to automatic review settings November 25, 2026 11:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The constructor-name check accepts an array, which causes stack-header sanitization to throw and prevents the original exception from reaching the uncaught-exception listener.

1 open issue
What changed in this PR

This PR improves GitHub Desktop’s renderer crash diagnostics and prevents benign ResizeObserver loop notifications from triggering fatal errors, addressing the missing-error-details path reported in #20760 and #21311.

Changes:

  • Preserve window.onerror messages and source locations, and improve non-Error formatting.
  • Handle ResizeObserver loop notifications as non-fatal, reporting at most once per renderer session.
  • Defer Tooltip resize updates to animation frames and add regression coverage for scheduling, cleanup, and error handling.
File Description
app/​test/​unit/​ui/​uncaught-exception-test.ts Tests error normalization, bridge behavior, and non-fatal loop handling.
app/​test/​unit/​ui/​tooltip-test.tsx Tests deferred resize updates, coalescing, and cleanup.
app/​test/​unit/​source-map-support-test.ts Tests non-Error diagnostics and source-location mapping.
app/​src/​ui/​lib/​uncaught-exception.ts Adds error normalization and renderer exception handlers.
app/​src/​ui/​lib/​tooltip.tsx Defers resize updates and cancels pending work on cleanup.
app/​src/​ui/​index.tsx Installs the new renderer error-handling pipeline.
app/​src/​lib/​source-map-support.ts Expands diagnostic formatting and exports source-location mapping.

Review effort: Balanced

Comment thread app/src/lib/source-map-support.ts Resolved
Review feedback: F1 (#23228 (comment)).

getConstructorName checked `typeof ctor === 'function' && ctor.name.length > 0`
without verifying `typeof ctor.name === 'string'`. Because Function.prototype.name
is configurable, a constructor whose `name` property was redefined to a non-string
with a positive `.length` (such as an array) passed the check and returned a
non-string value as `error.name`. That broke the `string` return contract of
`withSourceMappedStack` and threw `TypeError: text.replace is not a function`
inside `sanitizeStackHeaderText` when `normalizeWindowError` formatted a
synthetic stack header. This defect was introduced by this PR.

Read `ctor.name` once via `safeReadProperty(ctor, 'name')` and return it only
when `typeof nameProp.value === 'string' && nameProp.value.length > 0`, falling
back to `undefined` otherwise. Added regression tests covering both
`withSourceMappedStack` and `normalizeWindowError` with a non-string
`constructor.name`.

Validation:
- Regression tests reproduced both failures before the fix and passed after.
- `npm test -- app/test/unit/source-map-support-test.ts app/test/unit/ui/uncaught-exception-test.ts app/test/unit/ui/tooltip-test.tsx`: 30/30 passed.
- `npx tsc --noEmit`: passed.
- `npm run lint`: passed.
@sergiou87
sergiou87 marked this pull request as ready for review November 25, 2026 13:24
@sergiou87
sergiou87 requested a review from a team as a code owner November 25, 2026 13:24
@sergiou87
sergiou87 requested a review from babakks November 25, 2026 13:24
@sergiou87
sergiou87 requested a review from niik November 25, 2026 16:01
@sergiou87
sergiou87 enabled auto-merge November 25, 2026 17:20
@sergiou87
sergiou87 merged commit b668ecb into development Nov 28, 2026
22 of 23 checks passed
@sergiou87
sergiou87 deleted the unknown-unknown-error branch November 28, 2026 23:24
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.

4 participants