Skip to content

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

Closed

Description

@gtritchie

Summary

In the Electron main process, ten promise rejection handlers pass logger().logError to .catch() as a detached method reference:

this.loadUrl(this.options.baseUrl ?? '').catch(logger().logError);

WinstonLogger.logError is implemented as this.logErrorAtLevel('error', err) (src/node/desktop/src/core/winston-logger.ts:185-187). When the method is invoked detached from its instance, this is undefined, so the catch handler itself throws:

(node:3872) UnhandledPromiseRejectionWarning: TypeError: Cannot read properties of undefined (reading 'logErrorAtLevel')
    at logError (/usr/lib/rstudio/resources/app/.webpack/main/index.js:14:281461)

Two consequences:

  1. The original rejection is masked. Whatever failed (a loadUrl or executeJavaScript rejection) is replaced by this meta-error, so the log never shows the real problem. This made [Electron] Blank window on startup after GPU crash fix (v2026.06.0+242 on Ubuntu 22.04) #18323 harder to diagnose: the reporter's log shows only the logErrorAtLevel TypeError instead of the underlying failure.
  2. The closeEvent path can leave a zombie process. In MainWindow.closeEvent (src/node/desktop/src/main/main-window.ts:342-356), if executeJavaScript('!!window.desktopHooks') rejects (e.g. the renderer already crashed), the throwing catch handler means neither quit() nor this.quitConfirmed = true ever runs, consistent with the process staying alive after the window is gone as observed in [Electron] Blank window on startup after GPU crash fix (v2026.06.0+242 on Ubuntu 22.04) #18323.

Call sites

All on main as of this writing:

  • src/node/desktop/src/main/main-window.ts: 352, 355, 371, 385, 413
  • src/node/desktop/src/main/satellite-window.ts: 67, 77, 84, 111, 114

Fix

Wrap the call so the method is invoked on its instance:

.catch((err) => logger().logError(err));

Reproduction

Any rejection reaching one of these handlers triggers it. For example, force the main window's renderer to crash (or close the window while the webContents is destroyed) so executeJavaScript rejects in closeEvent; the console shows the logErrorAtLevel TypeError as an unhandled rejection instead of the original error.

Observed in the wild in #18323 (RStudio 2026.06.0+242, Ubuntu 22.04).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions