{"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":null,"httpStatus":null,"severity":"error","filePath":"src/services/integrations/AntigravityCliHooksInstaller.ts","lineNumber":176,"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// Read the standalone `hooks.json` agy loads. Returns the event→groups map\n// (the whole file). Empty/missing file → {}. Genuinely corrupt (non-empty,\n// unparseable) content throws so we never clobber a user's hand-edited hooks.\nfunction readAntigravityHooksConfig(): AntigravityHooksConfig {\n  if (!existsSync(GEMINI_HOOKS_CONFIG_PATH)) {\n    return {};\n  }\n  const content = readFileSync(GEMINI_HOOKS_CONFIG_PATH, 'utf-8');\n  if (!content.trim()) {\n    return {};","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/services/integrations/AntigravityCliHooksInstaller.ts#L158-L194","documentation":"readAntigravitySettings parses the shared Gemini/Antigravity settings JSON file. If the file exists but JSON.parse fails, the error is logged and re-thrown as a plain Error naming the offending path. The installer deliberately refuses to rewrite the file because doing so would destroy the user's settings it cannot parse.","triggerScenarios":"Installing Antigravity hooks when GEMINI_SETTINGS_PATH contains malformed JSON — manual edits, merge-conflict markers, trailing commas, or a truncated write from a crashed process.","commonSituations":"Users hand-editing settings.json and introducing syntax errors, another tool writing non-JSON content, or concurrent writers corrupting the file.","solutions":["Open the file at GEMINI_SETTINGS_PATH (usually ~/.gemini/settings.json) and fix the JSON syntax error.","Validate the file with a JSON linter or `JSON.parse` in a REPL before retrying the install.","Restore the file from backup, or delete it and let the installer recreate it (losing existing settings).","Re-run the installer once the file parses cleanly."],"exampleFix":"// before (settings.json)\n{ \"theme\": \"dark\",, }\n\n// after\n{\n  \"theme\": \"dark\"\n}","handlingStrategy":"validation","validationCode":"import { readFileSync } from 'fs';\ntry {\n  JSON.parse(readFileSync(GEMINI_SETTINGS_PATH, 'utf8'));\n} catch (e) {\n  console.error(`Fix JSON in ${GEMINI_SETTINGS_PATH} before installing hooks:`, e.message);\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await installer.install();\n} catch (e) {\n  if (String(e.message).includes('Corrupt JSON')) {\n    console.error(`Edit ${GEMINI_SETTINGS_PATH} and fix the JSON syntax, then retry.`);\n  } throw e;\n}","preventionTips":["Validate settings.json with a JSON linter after every manual edit.","Avoid hand-editing settings while an installer might be writing it.","Keep a backup of settings.json before running installers."],"tags":["json","settings-file","antigravity","install"],"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"}