jackwener/OpenCLI · error · CommandExecutionError
Failed to parse settings.json: ${e.message}
Error message
Failed to parse settings.json: ${e.message} What it means
Error "Failed to parse settings.json: ${e.message}" thrown in jackwener/OpenCLI.
Source
Thrown at clis/antigravity/storage.js:358
strategy: Strategy.LOCAL,
browser: false,
args: [],
columns: STORAGE_COLUMNS,
func: async () => {
if (!fs.existsSync(AG_SETTINGS_JSON)) {
throw new CommandExecutionError(`settings.json not found: ${AG_SETTINGS_JSON}`, '');
}
const raw = fs.readFileSync(AG_SETTINGS_JSON, 'utf-8');
// VSCode allows JSONC (line + block comments + trailing commas).
// Strip comments and trailing commas before parsing.
const stripped = raw
.replace(/\/\*[\s\S]*?\*\//g, '') // block comments
.replace(/^\s*\/\/.*$/gm, '') // line comments (full line)
.replace(/([^:"])\/\/.*$/gm, '$1') // line comments (after code)
.replace(/,(\s*[}\]])/g, '$1'); // trailing commas
let obj;
try { obj = JSON.parse(stripped); } catch (e) {
throw new CommandExecutionError(`Failed to parse settings.json: ${e.message}`, '');
}
const rows = [];
for (const [k, v] of Object.entries(obj)) {
rows.push({ Field: k, Value: typeof v === 'object' ? JSON.stringify(v) : String(v) });
}
return rows;
},
});
View on GitHub (pinned to 49907e53dc)
Solutions
- Open settings.json and fix or remove the invalid JSON (trailing commas, comments, unquoted keys)
- Restore settings.json from a backup or delete it to regenerate defaults
- Validate with a JSON linter before saving
Defensive patterns
Strategy: try-catch
Validate before calling
import * as fs from 'node:fs';
const raw = fs.readFileSync(settingsPath, 'utf-8');
const stripped = raw
.replace(/\/\*[\s\S]*?\*\//g, '')
.replace(/^\s*\/\/.*$/gm, '')
.replace(/([^:"])\/\/.*$/gm, '$1')
.replace(/,(\s*[}\]])/g, '$1');
try { JSON.parse(stripped); } catch (e) {
console.error(`settings.json will not parse even after JSONC stripping: ${e.message}`);
} Type guard
function isParsableJsonc(text) {
try {
const stripped = text.replace(/\/\*[\s\S]*?\*\//g, '')
.replace(/^\s*\/\/.*$/gm, '')
.replace(/([^:"])\/\/.*$/gm, '$1')
.replace(/,(\s*[}\]])/g, '$1');
JSON.parse(stripped);
return true;
} catch { return false; }
} Try / catch
try {
await cli.run(['antigravity', 'settings-read']);
} catch (e) {
if (String(e.message).startsWith('Failed to parse settings.json')) {
console.error(`Malformed settings.json: ${e.message}. Fix syntax at the reported position.`);
} else throw e;
} Prevention
- Validate settings.json with a JSONC-aware linter after hand-editing
- Beware the regex stripper can mangle URLs in values (// inside strings) — keep URL settings on lines where ([^:"])// won't match, or verify output
- Keep a backup of settings.json before bulk edits
When it happens
Trigger: Thrown at clis/antigravity/storage.js:358 when the library encounters an invalid state.
Common situations: See trigger scenarios.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/7894f888e8c6300e.
Report an issue: GitHub.