Skip to content

Fix detached logger().logError in desktop promise catch handlers - #18392

Merged
gtritchie merged 2 commits into
mainfrom
bugfix/18391-detached-logerror-callback
Jul 29, 2026
Merged

gtritchie merged 2 commits into
mainfrom
bugfix/18391-detached-logerror-callback

Conversation

@gtritchie

Copy link
Copy Markdown
Member

Fixes #18391.

What this changes

Ten call sites in main-window.ts and satellite-window.ts passed logger().logError directly to .catch(). The method reads this.logErrorAtLevel, so when a promise rejected, the detached call threw TypeError: Cannot read properties of undefined (reading 'logErrorAtLevel') inside the catch handler — replacing the original rejection with an unhandled meta-error and hiding the real failure (as seen in the logs on #18323). Each site now invokes the method on its logger instance via an arrow function, which also picks up the current logger at rejection time rather than at registration time.

In MainWindow.closeEvent, a rejected !!window.desktopHooks probe means the renderer is unreachable (e.g. it crashed). That path now logs the error and quits — matching the existing missing-desktopHooks branch — instead of leaving a headless process running after the window closes.

To keep the pattern from coming back, the desktop ESLint config now enables the type-aware @typescript-eslint/unbound-method rule, which flags every detached method reference of this kind. Two adaptations for spots that were already safe: minimal-window.ts's parentWindowDestroyed is now an arrow property (replacing its manual constructor .bind), and test files are exempted because sinon assertions take stub method references by design.

Tests

  • Two new unit tests for closeEvent with a rejecting renderer probe: the original error reaches the log sink, and the app quits instead of lingering. Both fail without the fix.
  • Full desktop suite passes (447), plus npm run lint and npm run typecheck.

Ten call sites in main-window.ts and satellite-window.ts passed
logger().logError directly to .catch(). The method reads
this.logErrorAtLevel, so invoking it detached from its instance threw
TypeError: Cannot read properties of undefined (reading
'logErrorAtLevel') inside the catch handler, replacing the original
rejection with an unhandled meta-error and hiding the real failure.

Wrap each call site in an arrow function so logError is invoked on its
logger instance (also picking up the current logger at rejection time
rather than at registration time).

In MainWindow.closeEvent, a rejected '!!window.desktopHooks' probe means
the renderer is unreachable (e.g. it crashed), so treat it like a
missing desktopHooks handler: log the error and quit, rather than
leaving a headless process behind after the window closes.

Addresses #18391
Guard against reintroducing detached method references like the
.catch(logger().logError) sites fixed for #18391. The rule is
type-aware and flagged every one of those call sites.

Adapt the two spots the rule flags that were already safe:

- minimal-window.ts bound parentWindowDestroyed manually in the
  constructor before passing it to the parent's event emitter; convert
  it to an arrow property so the reference is inherently bound and the
  manual bind is unnecessary.
- test files are exempted: sinon assertions take stub method references
  (e.g. sandbox.assert.calledOnce(stub.setSize)), a benign idiom that
  trips the rule.

Addresses #18391
@gtritchie gtritchie added this to the 2026.08 (Yellow Yarrow) milestone Jul 29, 2026
@gtritchie
gtritchie requested a review from kevinushey July 29, 2026 17:51
@posit-snyk-bot

posit-snyk-bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions

Copy link
Copy Markdown

RStudio E2E - all platforms

1 test(s) failed

###################- 99% pass rate

Passed Failed Skipped Flaky
1896 1 367 2
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
❌ desktop-linux 472 1 88 1
✅ desktop-macos 468 0 94 1
✅ desktop-windows 477 0 91 0
✅ server-linux 459 0 94 0
✅ setup 20 0 0 0
View / download the full report

View report online -- opens in the browser, no download needed. Available for 14 days.

Download playwright-report.zip -- extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


All platforms - commit dfc89d46132a7542ae50c63732cd62f874970867 - Run #381

@gtritchie
gtritchie merged commit 5771b42 into main Jul 29, 2026
26 of 27 checks passed
@gtritchie
gtritchie deleted the bugfix/18391-detached-logerror-callback branch July 29, 2026 19:30
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.

Electron: .catch(logger().logError) detaches the method, so logging a rejection throws and masks the original error

2 participants