Harden data safety: awaited saves, atomic writes, corruption recovery, rolling backups - #144
Open
tahabasri wants to merge 1 commit into
Open
Harden data safety: awaited saves, atomic writes, corruption recovery, rolling backups#144tahabasri wants to merge 1 commit into
tahabasri wants to merge 1 commit into
Conversation
…, rolling backups - Fix handleCommand: 'new Promise(callback)' treated command bodies as executors whose resolve/reject were never called, so the promise never settled and async command errors bypassed the handler entirely. Chain through Promise.resolve().then(callback) so rejections are caught, shown to the user, and logged with a stack. - Make DataAccess.save async end-to-end and await it in SnippetsProvider.sync(): memento.update was fire-and-forget, so save failures were silently swallowed and the tree refreshed from a state that never committed. All provider mutations now propagate the save promise to their callers. - FileDataAccess: atomic writes (write temp file, then rename) so a crash mid-write can never truncate snippets.json; on unparseable JSON the persistent workspace backend now preserves the file as *.corrupt-<timestamp>, reseeds an empty root and notifies the user instead of dying during activation. Transient import instances keep throwing so a bad import source is never overwritten. - New BackupManager: rolling timestamped backups (10 kept per view) in globalStorage before destructive operations (import, troubleshoot, folder deletion) and at most one automatic snapshot per day. - New 'Snippets: Open Backups Folder' command to make backups discoverable (command palette + view overflow menu). - Tests for atomic saves, corruption recovery and backup rotation; bump @vscode/test-electron 2.3.4 -> 2.5.2 (old version cannot launch current VS Code stable).
Draft
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.
What
The extension's most serious recurring bug class is silent data loss (#31, #33, #66, #101, #119, #129). This PR hardens the whole persistence path:
handleCommand:new Promise(callback)treated command bodies as executors whose resolve/reject were never called — the promise never settled and async command errors bypassed the handler entirely. Now chains throughPromise.resolve().then(callback)so rejections are surfaced to the user and logged with a stack.memento.update()was fire-and-forget, so save failures were silently swallowed and the tree refreshed from a state that never committed.DataAccess.saveis now async andSnippetsProvider.sync()awaits it; all provider mutations propagate the save promise.FileDataAccesswrites to a temp file then renames, so a crash mid-write can never truncate.vscode/snippets.json.*.corrupt-<timestamp>, reseeds an empty root and notifies the user. Transient import instances keep throwing so a bad import source is never overwritten.BackupManager): timestamped snapshots (10 kept per view) in global storage before destructive operations (import, troubleshoot, folder deletion) plus at most one automatic snapshot per day. New Snippets: Open Backups Folder command makes them discoverable.Tests
@vscode/test-electronbumped 2.3.4 → 2.5.2 (the old version cannot launch current VS Code stable builds).🤖 Generated with Claude Code