Egonex-AI/Understand-Anything · error · Error
fingerprints.json existed and was non-empty but loaded as {}
Error message
fingerprints.json existed and was non-empty but loaded as {} — refusing to overwrite What it means
Thrown by the auto-update hook's fingerprint-update logic when fingerprints.json existed and was non-empty on disk but the in-memory load ('before') came out as zero entries. This is a deliberate guard against a silent load failure: writing the freshly-computed subset would clobber all pre-existing entries. The hook refuses to overwrite rather than destroy the store.
Source
Thrown at understand-anything-plugin/hooks/auto-update-prompt.md:287
// `filesToReanalyze` may include paths that were deleted in this commit —
// handle both branches inline rather than expecting a separate deleted list.
for (const filePath of filesToReanalyze) {
const fullPath = path.join(PROJECT_ROOT, filePath);
if (!existsSync(fullPath)) {
delete all[filePath];
continue;
}
const content = readFileSync(fullPath, 'utf-8');
const contentHash = createHash('sha256').update(content).digest('hex');
// Extract functions, classes, imports, exports via the same regex as Phase 1.
all[filePath] = { contentHash, functions, classes, imports, exports };
}
// 3. GUARD against silent load failure: if fingerprints.json existed and was
// non-empty but `before` came out as 0, refuse to overwrite — something
// went wrong reading the file and writing now would clobber every entry.
if (existedAndNonEmpty && before === 0) {
throw new Error('fingerprints.json existed and was non-empty but loaded as {} — refusing to overwrite');
}
// 4. SAVE ALL entries back (full dict — not just the patched subset)
writeFileSync(fpPath, JSON.stringify(all, null, 2));
console.log(`Fingerprints: ${before} → ${Object.keys(all).length}`);
```
The `existedAndNonEmpty && before === 0` guard catches the silent-load-failure case before it corrupts the store. If the count shrinks from N to a small number that matches the batch size, the LOAD step was skipped — abort the write rather than persist the wrong dict.
4. Clean up intermediate files:
```bash
INTERMEDIATE_DIR="$UA_DIR/intermediate"
if [ -n "$PROJECT_ROOT" ] && [ -d "$INTERMEDIATE_DIR" ]; then
rm -rf "$INTERMEDIATE_DIR"
fi
```
5. Report a summary:View on GitHub (pinned to 32944829e7)
Solutions
- Inspect fingerprints.json for validity (parse it as JSON); repair or restore from version control if corrupt.
- If the store is genuinely stale and you want to rebuild it, back it up then delete it so existedAndNonEmpty is false and the guard no longer trips.
- Ensure no other process is writing fingerprints.json concurrently with the hook.
- Re-run the hook after the file is in a valid state — the full dict will be rewritten, not just a batch subset.
Example fix
# before — guard trips because fingerprints.json is corrupt but non-empty # after — repair or reset the store, then re-run mv .ua/fingerprints.json .ua/fingerprints.json.bak && rm .ua/fingerprints.json # re-run the auto-update hook
Defensive patterns
Strategy: validation
Validate before calling
const existedAndNonEmpty = existsSync(fpPath) && statSync(fpPath).size > 0;
let before = 0;
if (existedAndNonEmpty) {
try { before = Object.keys(JSON.parse(readFileSync(fpPath, 'utf-8'))).length; }
catch { before = 0; }
}
if (existedAndNonEmpty && before === 0) { /* abort: corrupt store, do not write */ } Type guard
function isFingerprintStore(v: unknown): v is Record<string, unknown> {
return v !== null && typeof v === 'object' && !Array.isArray(v);
} Prevention
- Treat the guard as load-bearing: never bypass existedAndNonEmpty && before === 0.
- Back up fingerprints.json before re-running the hook when this fires.
- Ensure no concurrent process writes fingerprints.json during the hook.
When it happens
Trigger: fingerprints.json is non-empty but unreadable as JSON in the load step (corruption, encoding issue, BOM, partial write), yet the readFileSync did not throw — yielding an empty object. The guard then sees existedAndNonEmpty === true and before === 0 and aborts before writeFileSync.
Common situations: A previous run was killed mid-write leaving invalid JSON; an editor or merge tool re-saved fingerprints.json with formatting the loader cannot parse; concurrent processes racing on the file; disk/filesystem corruption; a sync tool writing a placeholder empty object.
Related errors
AI-assisted analysis of Egonex-AI/Understand-Anything@32944829e7 (2026-08-12).
Data as JSON: /api/errors/824f5ecb86f7aa14.
Report an issue: GitHub.