{"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":111,"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    // Write whitelist. Secrets are deliberately absent: the Observation TV token,\n    // and the Chroma / Telegram / CloudSync keys. POST /api/settings has no\n    // authentication, so any page the user visits could set one of its choosing.\n    // Keeping them off this list means only the filesystem or the env can set them.\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',","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/services/worker/http/routes/SettingsRoutes.ts#L93-L129","documentation":"When reading the on-disk settings file for a GET/merge path, a JSON parse failure (including BOM-related issues, though parseJsonWithBom handles BOM) is caught and converted to a 500 telling the user the settings file is corrupted and to delete settingsPath to reset it. The worker refuses to guess at partial settings content.","triggerScenarios":"A request path that readFileSync's the settings JSON file and hits a parse error: truncated file from a crash mid-write, hand-edited JSON with a syntax mistake, encoding artifacts, or a file that is not JSON at all.","commonSituations":"Manual editing of the settings file with a trailing comma or comment; disk-full or power loss during a settings write; another tool writing non-JSON content to the settings path; copy-paste from a rich-text editor introducing smart quotes.","solutions":["Open the file at the path named in the error and fix the JSON syntax error (the server log includes the parse error details)","Back up the file, delete it, and let the worker recreate defaults, then reapply settings via the API","Validate the JSON with a linter/parser before saving manual edits","Ensure the process writing settings uses atomic writes (write temp + rename) to avoid truncation"],"exampleFix":"// before (settings.json)\n{ \"autoCompact\": true, }\n// after\n{ \"autoCompact\": true }","handlingStrategy":"try-catch","validationCode":"import { readFileSync } from 'fs';\ntry { JSON.parse(readFileSync(settingsPath, 'utf-8')); } catch (e) { console.error(`${settingsPath} is not valid JSON: ${(e as Error).message}`); }","typeGuard":"function isValidSettingsFile(raw: string): boolean {\n  try { JSON.parse(raw); return true; } catch { return false; }\n}","tryCatchPattern":"try {\n  const settings = await updateSettings(changes);\n} catch (e) {\n  if (String(e).includes('Settings file is corrupted')) {\n    // back up the file, delete it to reset, then reapply settings\n  }\n}","preventionTips":["Edit settings via the API/UI rather than hand-editing the JSON file","Validate JSON with a linter before saving manual edits","Use atomic writes (write temp file + rename) when modifying settings on disk","Keep a backup of settings.json before bulk edits or upgrades"],"tags":["http","json","settings","file-corruption"],"backgroundTag":"json-parse-error","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}