{"record":{"id":"c641d001aff4b812","repo":"thedotmack/claude-mem","slug":"settings-file-is-corrupted-delete-settingspath","errorCode":null,"errorMessage":"Settings file is corrupted. Delete ${settingsPath} to reset.","messagePattern":"Settings file is corrupted\\. Delete (.+?) to reset\\.","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"src/services/worker/http/routes/SettingsRoutes.ts","lineNumber":69,"sourceCode":"      res.status(400).json({\n        success: false,\n        error: validation.error\n      });\n      return;\n    }\n\n    const settingsPath = paths.settings();\n    this.ensureSettingsFile(settingsPath);\n    let settings: any = {};\n\n    if (existsSync(settingsPath)) {\n      const settingsData = readFileSync(settingsPath, 'utf-8');\n      try {\n        settings = parseJsonWithBom(settingsData);\n      } catch (parseError) {\n        const normalizedParseError = parseError instanceof Error ? parseError : new Error(String(parseError));\n        logger.error('HTTP', 'Failed to parse settings file', { settingsPath }, normalizedParseError);\n        res.status(500).json({\n          success: false,\n          error: `Settings file is corrupted. Delete ${settingsPath} to reset.`\n        });\n        return;\n      }\n    }\n\n    const settingKeys = [\n      'CLAUDE_MEM_MODEL',\n      'CLAUDE_MEM_CONTEXT_OBSERVATIONS',\n      'CLAUDE_MEM_WORKER_PORT',\n      'CLAUDE_MEM_WORKER_HOST',\n      'CLAUDE_MEM_PROVIDER',\n      'CLAUDE_MEM_CLAUDE_AUTH_METHOD',\n      'CLAUDE_MEM_GEMINI_API_KEY',\n      'CLAUDE_MEM_GEMINI_MODEL',\n      'CLAUDE_MEM_GEMINI_RATE_LIMITING_ENABLED',\n      'CLAUDE_MEM_OPENROUTER_API_KEY',","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/e2d1df569a8f04075d40e92461128ece7cf04c82/src/services/worker/http/routes/SettingsRoutes.ts#L51-L87","documentation":"HTTP 500 from the settings GET/PUT handler when the settings file at paths.settings() exists but parseJsonWithBom cannot parse it — i.e. the file is present and readable yet not valid JSON (BOM is tolerated; syntax is not). The worker logs the parse error with the path and tells the user to delete the file to reset to defaults.","triggerScenarios":"Hand-editing settings.json and leaving a trailing comma, unquoted key or unclosed brace; an editor or sync tool writing partial content; merging conflict markers left in the file; the file truncated by a crash mid-write.","commonSituations":"Users tweaking CLAUDE_MEM_MODEL or port values manually; dotfile managers syncing a broken file across machines; two processes writing the file concurrently so one reads a half-written state.","solutions":["Run a JSON validator on the path shown in the error (settingsPath) and fix the syntax error","Or delete the file to reset all settings to defaults, then re-apply your changes one at a time","Prefer the settings API over hand-editing so writes are always well-formed"],"exampleFix":"// before: settings.json\n{ \"CLAUDE_MEM_WORKER_PORT\": 37777, }  // trailing comma -> 500\n\n// after\n{ \"CLAUDE_MEM_WORKER_PORT\": 37777 }","handlingStrategy":"validation","validationCode":"import { readFileSync } from 'node:fs';\nfunction settingsFileValid(path: string): boolean {\n  try { JSON.parse(readFileSync(path, 'utf-8').replace(/^\\uFEFF/, '')); return true; }\n  catch { return false; }\n}","typeGuard":"function isSettingsCorrupt(body: unknown, status: number): boolean {\n  return status === 500 && typeof body === 'object' && body !== null &&\n    String((body as { error?: string }).error).startsWith('Settings file is corrupted');\n}","tryCatchPattern":null,"preventionTips":["Edit settings through the settings API, never by hand-editing settings.json","Validate the file with a JSON linter after any manual edit","Back up settings.json before upgrades or sync-tool sweeps of the home directory"],"tags":["http-500","settings","json-parse","config-file"],"backgroundTag":"config-file-corrupt-json","analyzedSha":"e2d1df569a8f04075d40e92461128ece7cf04c82","analyzedAt":"2026-08-20T23:58:13.836Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}