{"record":{"id":"6620b2666e93de6d","repo":"thedotmack/claude-mem","slug":"corrupt-json-file-refusing-to-overwrite-filepa","errorCode":null,"errorMessage":"Corrupt JSON file, refusing to overwrite: ${filePath}: ${error instanceof Error ? error.message : String(error)}","messagePattern":"Corrupt JSON file, refusing to overwrite: (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/utils/json-utils.ts","lineNumber":13,"sourceCode":"import { existsSync, readFileSync } from 'fs';\nimport { parseJsonWithBom } from '../shared/atomic-json.js';\n\nexport function readJsonSafe<T>(filePath: string, defaultValue: T): T {\n  if (!existsSync(filePath)) return defaultValue;\n  try {\n    // Windows tooling (PowerShell 5.1, some editors) may rewrite JSON with a\n    // UTF-8 BOM. Node/Bun decode that to U+FEFF at offset 0, which JSON.parse\n    // rejects. Strip on read so install/uninstall and other callers survive.\n    // See #3013.\n    return parseJsonWithBom<T>(readFileSync(filePath, 'utf-8'));\n  } catch (error: unknown) {\n    throw new Error(`Corrupt JSON file, refusing to overwrite: ${filePath}: ${error instanceof Error ? error.message : String(error)}`);\n  }\n}\n","sourceCodeStart":1,"sourceCodeEnd":16,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d768ba364302d12b76e69e4f021f0bb1d2d50ed6/src/utils/json-utils.ts#L1-L16","documentation":"Error \"Corrupt JSON file, refusing to overwrite: ${filePath}: ${error instanceof Error ? error.message : String(error)}\" thrown in thedotmack/claude-mem.","triggerScenarios":"Fires when a JSON file that is about to be rewritten (settings, hooks config, marketplace json) fails to parse, so the write is refused to avoid destroying user data with a truncated or hand-corrupted file. Guard at src/utils/json-utils.ts:13 protects against clobbering configs after partial writes, manual edits with syntax errors, or encoding corruption.","commonSituations":"See trigger scenarios.","solutions":["Fix or delete the corrupt JSON file manually, then rerun the command; the error message includes the file path and parse error.","Restore the file from a backup or regenerate it (e.g. rerun install) if its contents are unrecoverable."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"d768ba364302d12b76e69e4f021f0bb1d2d50ed6","analyzedAt":"2026-08-12T23:52:55.241Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}