feat(store): _saveDisabled latch and stronger corruption-wipe coverage

This commit is contained in:
dev
2026-06-01 16:16:21 -05:00
parent 231890a9e0
commit e39758c1af
2 changed files with 25 additions and 1 deletions
+4 -1
View File
@@ -11,6 +11,7 @@ export class Store {
if (!storage) throw new Error('Store requires a storage object');
this.storage = storage;
this.onWarn = onWarn;
this._saveDisabled = false;
this.targets = this._loadJson(KEY_TARGETS, {});
this.history = this._loadJson(KEY_HISTORY, {});
this.prefs = this._mergePrefs(this._loadJson(KEY_PREFS, null));
@@ -34,11 +35,13 @@ export class Store {
}
_saveJson(key, value) {
if (this._saveDisabled) return false;
try {
this.storage.setItem(key, JSON.stringify(value));
return true;
} catch (e) {
this.onWarn(`[tat] failed to persist ${key}: ${e.message}`);
this.onWarn(`[tat] failed to persist ${key}: ${e.message}; further saves disabled for this session`);
this._saveDisabled = true;
return false;
}
}