Skip to content

fix(desktop): guard window-state store writes against disk-write failures#3304

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/guard-window-state-disk-writes
Draft

fix(desktop): guard window-state store writes against disk-write failures#3304
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-code/guard-window-state-disk-writes

Conversation

@posthog

@posthog posthog Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Problem

A full disk on one user's machine crashed the Electron main process. When the app saves window position/size, saveWindowState calls into electron-store, which does a synchronous atomic writeFileSync. That write threw ENOSPC: no space left on device, and because it runs inside the scheduleSaveWindowState setTimeout callback (and window event handlers) with no try/catch, the throw became an uncaught exception in the main process and got reported to error tracking. The same unguarded pattern existed in the utils/store.ts setters (saveZoomLevel, saveFullScreenState, setRestoreFullScreenOnNextLaunch).

Why: Window-state persistence is non-critical — a failed write should never be able to take down the main process or spam error tracking. The disk-full condition is on the user's side and can't be fixed in-app, but a transient FS error shouldn't crash the app.

Changes

  • Added a shared setWindowStateKey helper in utils/store.ts that wraps windowStateStore.set(...) in try/catch and logs failures via the scoped logger instead of letting them propagate.
  • Routed saveWindowState (window.ts) and the utils/store.ts setters through this helper.

How did you test this?

  • pnpm --filter code typecheck — passes.
  • pnpm biome check on both changed files — no issues.

Created with PostHog Code from an inbox report

…ures

Window-state persistence goes through electron-store's synchronous atomic
`writeFileSync`, which can throw on transient filesystem errors (e.g. a full
disk). These writes ran inside a `setTimeout` callback and event handlers with
no try/catch, so a throw became an uncaught exception in the Electron main
process, crashing it and spamming error tracking.

Route the window-state writes through a shared `setWindowStateKey` helper that
catches and logs via the scoped logger, and use it in `saveWindowState` and the
`utils/store.ts` setters. Persistence is non-critical, so a failed write should
never take down the main process.

Generated-By: PostHog Code
Task-Id: b3d5abbb-2f47-4171-bdf8-a7464bf6c6e1
@trunk-io

trunk-io Bot commented Jul 9, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 66ca079.

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.

0 participants