Repository navigation
Archive a settings file that fails to deserialize instead of deleting it [patch] - #337
Merged
Merged
Conversation
… it [patch] LoadOrCreate deleted the main file on a JsonException and retried, but a successful save removes the backup, so that file was usually the only copy of the user's data and a hand edit or a model change in an app update silently wiped it. Move it aside to <file>.corrupt.<timestamp> with the same counter loop TryRestoreFrom uses, now shared as AppData.Archive. Fixes #314 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DCzUAHg8icJNNp7WtR51Um
|
This was referenced Oct 6, 2026
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 #314
What was wrong
When
AppData<T>.LoadOrCreatehit aJsonException, it deleted the main file and retried. A successful save removes the.bkfile, so in practice that file was the only copy of the user's data. Two ordinary events triggered this, and nothing was logged or left on disk afterwards:Change
TryRestoreFromis nowAppData.Archive(filePath, label), which returns the path it archived to.TryRestoreFromuses it with no label, so its behaviour is unchanged.LoadOrCreatearchives the unreadable file to<file>.corrupt.<yyyyMMdd_HHmmss>instead of deleting it. The retry still finds the main file missing and falls back to the temp file, then the backup, then defaults.TryRestoreFromcomment that described the old delete.Tests
TestLoadOrCreateArchivesAnUnreadableFileInsteadOfDeletingItfollows the issue's repro: save real data, break the JSON, thenLoadOrCreate. It asserts the defaults load and exactly one.corrupt.*archive holds the original content. With the delete restored, it fails atAssert.AreEqual(1, archived.Length).TestLoadOrCreateHandlesCorruptFileand the recovery tests.🤖 Generated with Claude Code
https://claude.ai/code/session_01DCzUAHg8icJNNp7WtR51Um
Generated by Claude Code