thedotmack/claude-mem · error

Corrupt JSON in , refusing to overwrite user settings

Error message

Corrupt JSON in ${GEMINI_SETTINGS_PATH}, refusing to overwrite user settings

What it means

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.

Solutions

  1. Open the file at GEMINI_SETTINGS_PATH (usually ~/.gemini/settings.json) and fix the JSON syntax error.
  2. Validate the file with a JSON linter or `JSON.parse` in a REPL before retrying the install.
  3. Restore the file from backup, or delete it and let the installer recreate it (losing existing settings).
  4. Re-run the installer once the file parses cleanly.

Example fix

// before (settings.json)
{ "theme": "dark",, }

// after
{
  "theme": "dark"
}
Defensive patterns

Strategy: validation

Validate before calling

import { readFileSync } from 'fs';
try {
  JSON.parse(readFileSync(GEMINI_SETTINGS_PATH, 'utf8'));
} catch (e) {
  console.error(`Fix JSON in ${GEMINI_SETTINGS_PATH} before installing hooks:`, e.message);
  process.exit(1);
}

Try / catch

try {
  await installer.install();
} catch (e) {
  if (String(e.message).includes('Corrupt JSON')) {
    console.error(`Edit ${GEMINI_SETTINGS_PATH} and fix the JSON syntax, then retry.`);
  } throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Users hand-editing settings.json and introducing syntax errors, another tool writing non-JSON content, or concurrent writers corrupting the file.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17). Data as JSON: /api/errors/33ca39b8342e7f46. Report an issue: GitHub.

Appendix: source

Thrown at src/services/integrations/AntigravityCliHooksInstaller.ts:176

    }],
  };
}

function readAntigravitySettings(): AntigravitySettingsJson {
  if (!existsSync(GEMINI_SETTINGS_PATH)) {
    return {};
  }

  const content = readFileSync(GEMINI_SETTINGS_PATH, 'utf-8');
  try {
    return JSON.parse(content) as AntigravitySettingsJson;
  } catch (error) {
    if (error instanceof Error) {
      logger.error('WORKER', 'Corrupt JSON in Antigravity CLI (shared Gemini) settings', { path: GEMINI_SETTINGS_PATH }, error);
    } else {
      logger.error('WORKER', 'Corrupt JSON in Antigravity CLI (shared Gemini) settings', { path: GEMINI_SETTINGS_PATH }, new Error(String(error)));
    }
    throw new Error(`Corrupt JSON in ${GEMINI_SETTINGS_PATH}, refusing to overwrite user settings`);
  }
}

function writeAntigravitySettings(settings: AntigravitySettingsJson): void {
  mkdirSync(GEMINI_CONFIG_DIR, { recursive: true });
  writeFileSync(GEMINI_SETTINGS_PATH, JSON.stringify(settings, null, 2) + '\n');
}

// Read the standalone `hooks.json` agy loads. Returns the event→groups map
// (the whole file). Empty/missing file → {}. Genuinely corrupt (non-empty,
// unparseable) content throws so we never clobber a user's hand-edited hooks.
function readAntigravityHooksConfig(): AntigravityHooksConfig {
  if (!existsSync(GEMINI_HOOKS_CONFIG_PATH)) {
    return {};
  }
  const content = readFileSync(GEMINI_HOOKS_CONFIG_PATH, 'utf-8');
  if (!content.trim()) {
    return {};

View on GitHub (pinned to d8bc9755e7)