Repository navigation
Fix detached logger().logError in desktop promise catch handlers - #18392
Merged
Merged
Conversation
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
Contributor
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
RStudio E2E - all platforms1 test(s) failed
View / download the full reportView report online -- opens in the browser, no download needed. Available for 14 days. Download playwright-report.zip -- extract and open
All platforms - commit |
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.
Fixes #18391.
What this changes
Ten call sites in
main-window.tsandsatellite-window.tspassedlogger().logErrordirectly to.catch(). The method readsthis.logErrorAtLevel, so when a promise rejected, the detached call threwTypeError: 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.desktopHooksprobe means the renderer is unreachable (e.g. it crashed). That path now logs the error and quits — matching the existing missing-desktopHooksbranch — 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-methodrule, which flags every detached method reference of this kind. Two adaptations for spots that were already safe:minimal-window.ts'sparentWindowDestroyedis now an arrow property (replacing its manual constructor.bind), and test files are exempted because sinon assertions take stub method references by design.Tests
closeEventwith a rejecting renderer probe: the original error reaches the log sink, and the app quits instead of lingering. Both fail without the fix.npm run lintandnpm run typecheck.