aboutsummaryrefslogtreecommitdiff
path: root/modules/core/module-memory-graph.js
diff options
context:
space:
mode:
Diffstat (limited to 'modules/core/module-memory-graph.js')
-rw-r--r--modules/core/module-memory-graph.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/modules/core/module-memory-graph.js b/modules/core/module-memory-graph.js
index 1cb0919..e802387 100644
--- a/modules/core/module-memory-graph.js
+++ b/modules/core/module-memory-graph.js
@@ -594,6 +594,12 @@ class MemoryGraphModule {
try {
const fs = this.terminal.fs;
if (!fs) return;
+ // MAINT-003: a corrupt store used to look exactly like a fresh one — fsReadJSON
+ // returns null on a parse failure, so the graph started empty with no warning and no
+ // copy of what was there. Quarantine anything unreadable first, then load what's left.
+ this._quarantineCorrupt('export.json');
+ this._quarantineCorrupt('nodes.json');
+ this._quarantineCorrupt('edges.json');
// Try loading from export first
const exportData = fs.fsReadJSON(`${this._indexPath}export.json`);
@@ -646,6 +652,25 @@ class MemoryGraphModule {
}
}
+ // MAINT-003: keep an unreadable store aside instead of starting fresh over it.
+ _quarantineCorrupt(name) {
+ try {
+ const fs = this.terminal.fs;
+ const p = `${this._indexPath}${name}`;
+ const raw = fs.readFile(p);
+ if (typeof raw !== 'string' || !raw.length) return false;
+ try { JSON.parse(raw); return false; } catch (e) {
+ const kept = p + '.corrupt';
+ fs.writeFile(kept, raw);
+ this.terminal.print(`⚠️ Memory graph store ${name} is unreadable — kept a copy at ${kept} and starting from what remains`, 'warning');
+ if (typeof fs.deleteFile === 'function') fs.deleteFile(p);
+ return true;
+ }
+ } catch (e) {
+ return false;
+ }
+ }
+
_saveNow() {
try {
const fs = this.terminal.fs;