{"record":{"id":"33ca39b8342e7f46","repo":"thedotmack/claude-mem","slug":"corrupt-json-in-gemini-settings-path-refusing","errorCode":null,"errorMessage":"Corrupt JSON in ${GEMINI_SETTINGS_PATH}, refusing to overwrite user settings","messagePattern":"Corrupt JSON in (.+?), refusing to overwrite user settings","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/services/integrations/AntigravityCliHooksInstaller.ts","lineNumber":118,"sourceCode":"    }],\n  };\n}\n\nfunction readAntigravitySettings(): AntigravitySettingsJson {\n  if (!existsSync(GEMINI_SETTINGS_PATH)) {\n    return {};\n  }\n\n  const content = readFileSync(GEMINI_SETTINGS_PATH, 'utf-8');\n  try {\n    return JSON.parse(content) as AntigravitySettingsJson;\n  } catch (error) {\n    if (error instanceof Error) {\n      logger.error('WORKER', 'Corrupt JSON in Antigravity CLI (shared Gemini) settings', { path: GEMINI_SETTINGS_PATH }, error);\n    } else {\n      logger.error('WORKER', 'Corrupt JSON in Antigravity CLI (shared Gemini) settings', { path: GEMINI_SETTINGS_PATH }, new Error(String(error)));\n    }\n    throw new Error(`Corrupt JSON in ${GEMINI_SETTINGS_PATH}, refusing to overwrite user settings`);\n  }\n}\n\nfunction writeAntigravitySettings(settings: AntigravitySettingsJson): void {\n  mkdirSync(GEMINI_CONFIG_DIR, { recursive: true });\n  writeFileSync(GEMINI_SETTINGS_PATH, JSON.stringify(settings, null, 2) + '\\n');\n}\n\n// Generic JSON-group merge — doesn't depend on event names, copied verbatim\n// from the removed GeminiCliHooksInstaller.ts.\nfunction mergeHooksIntoSettings(\n  existingSettings: AntigravitySettingsJson,\n  newHooks: AntigravityHooksConfig,\n): AntigravitySettingsJson {\n  const settings = { ...existingSettings };\n  if (!settings.hooks) {\n    settings.hooks = {};\n  }","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d768ba364302d12b76e69e4f021f0bb1d2d50ed6/src/services/integrations/AntigravityCliHooksInstaller.ts#L100-L136","documentation":"readAntigravitySettings() reads ~/.gemini/settings.json (shared between Gemini CLI and Antigravity CLI). If the file exists but JSON.parse fails, the installer deliberately refuses to overwrite the user's hand-edited settings and throws, because silently rewriting would destroy a partially-valid config. The original parse error is logged first, then re-thrown as a plain Error from the install flow.","triggerScenarios":"Running installAntigravityCliHooks (or the main installer's Antigravity path) when ~/.gemini/settings.json contains malformed JSON — stray trailing comma, unquoted keys, a pasted snippet with smart quotes, or a truncated file from a previous interrupted write.","commonSituations":"User manually edited settings.json and introduced a syntax error; another tool wrote partial JSON and crashed; file got corrupted by a merge conflict marker left in; an editor inserted a BOM or CRLF that breaks the parser on a strict platform.","solutions":["Open ~/.gemini/settings.json in an editor and fix the JSON syntax error (validate with a JSON linter or `node -e \"JSON.parse(require('fs').readFileSync(process.env.HOME+'/.gemini/settings.json','utf8'))\"`).","If you cannot salvage it, back up the file, replace it with `{}`, then re-run the installer.","Re-run `npx claude-mem@latest install` once the file parses cleanly."],"exampleFix":"// before — settings.json contains: { \"hooks\": { , } }\n\n// after — valid JSON\n{\n  \"hooks\": {}\n}\n// then re-run: npx claude-mem@latest install","handlingStrategy":"validation","validationCode":"import { readFileSync, existsSync } from 'fs';\n\nfunction isSettingsJsonValid(path: string): boolean {\n  if (!existsSync(path)) return true; // absent is fine\n  try { JSON.parse(readFileSync(path, 'utf-8')); return true; }\n  catch { return false; }\n}","typeGuard":"function isCorruptSettingsError(e: unknown): boolean {\n  return e instanceof Error && /Corrupt JSON in .*settings\\.json/i.test(e.message);\n}","tryCatchPattern":"try {\n  await installAntigravityCliHooks();\n} catch (e) {\n  if (e instanceof Error && /refusing to overwrite user settings/.test(e.message)) {\n    console.error(`${e.message}\\nFix or back up the settings file, then re-run install.`);\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Validate ~/.gemini/settings.json parses before running the installer.","Never hand-edit JSON without a linter; keep a backup before bulk edits.","Treat 'refusing to overwrite' as intentional data protection — fix the source file, don't suppress."],"tags":["config","json","filesystem","antigravity","gemini","installer"],"backgroundTag":null,"analyzedSha":"d768ba364302d12b76e69e4f021f0bb1d2d50ed6","analyzedAt":"2026-08-12T23:52:55.241Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}