jackwener/OpenCLI · error · CommandExecutionError
Failed to parse extensions.json: ${e.message}
Error message
Failed to parse extensions.json: ${e.message} What it means
This CommandExecutionError is thrown by the extensions-list command when TRAE_EXTENSIONS_JSON exists but JSON.parse fails on its contents. The caught SyntaxError message is embedded in the error so the developer can see the exact parse failure (position, unexpected token, etc.).
Source
Thrown at clis/trae-solo/workspaces-fs.js:92
access: 'read',
description: 'List VSCode extensions installed in Trae SOLO (~/.trae/extensions/extensions.json). Works while Trae is closed.',
domain: 'localhost',
browser: false,
strategy: Strategy.LOCAL,
args: [],
columns: ['Index', 'Workspace Id', 'Kind', 'Target', 'Modified', 'Id', 'Version', 'Source', 'Installed'],
func: async () => {
if (!fs.existsSync(TRAE_EXTENSIONS_JSON)) {
throw new CommandExecutionError(
`extensions.json not found: ${TRAE_EXTENSIONS_JSON}`,
'Trae SOLO has not installed any VSCode extensions yet.',
);
}
let arr;
try {
arr = JSON.parse(fs.readFileSync(TRAE_EXTENSIONS_JSON, 'utf-8'));
} catch (e) {
throw new CommandExecutionError(`Failed to parse extensions.json: ${e.message}`, '');
}
if (!Array.isArray(arr) || !arr.length) {
throw new EmptyResultError('trae-solo extensions-list', 'No extensions installed.');
}
return arr.map((e, i) => {
const ts = e?.metadata?.installedTimestamp;
const installed = ts ? new Date(ts).toISOString().replace('T', ' ').slice(0, 19) : '';
return {
Index: i + 1,
'Workspace Id': '',
Kind: '',
Target: '',
Modified: '',
Id: e?.identifier?.id || '?',
Version: e?.version || '',
Source: e?.metadata?.source || '',
Installed: installed,
};View on GitHub (pinned to 49907e53dc)
Solutions
- Inspect extensions.json with a JSON validator and fix the syntax error at the reported position
- Restore the file from backup, or back it up and delete it, then reinstall extensions to regenerate it
- If the file is JSONC (comments), strip comments before parsing or use a JSONC-aware parser
- Close Trae, verify file integrity, and reopen so Trae rewrites the file cleanly
Example fix
// before
try {
arr = JSON.parse(fs.readFileSync(TRAE_EXTENSIONS_JSON, 'utf-8'));
} catch (e) {
throw new CommandExecutionError(`Failed to parse extensions.json: ${e.message}`, '');
}
// after
const text = fs.readFileSync(TRAE_EXTENSIONS_JSON, 'utf-8').replace(/^\uFEFF/, '');
let arr;
try {
arr = JSON.parse(text);
} catch (e) {
console.error(`extensions.json corrupt (${e.message}); backing up, treating as empty`);
fs.copyFileSync(TRAE_EXTENSIONS_JSON, TRAE_EXTENSIONS_JSON + '.bak');
arr = [];
} Defensive patterns
Strategy: try-catch
Validate before calling
const text = fs.readFileSync(TRAE_EXTENSIONS_JSON, 'utf-8').replace(/^\uFEFF/, '');
try { JSON.parse(text); } catch (e) {
console.warn(`extensions.json is invalid JSON: ${e.message}`);
} Try / catch
try {
const rows = await runExtensionsList();
} catch (e) {
if (/Failed to parse extensions\.json/.test(e.message)) {
console.warn(`${e.message}; restore extensions.json from backup or reinstall extensions.`);
return [];
}
throw e;
} Prevention
- Never hand-edit extensions.json while Trae is running
- Validate the file with a JSON linter after manual edits
- Back up extensions.json before Trae upgrades or bulk extension operations
- Strip a leading BOM before parsing
- Check disk space to avoid truncated writes
When it happens
Trigger: extensions.json truncated by an interrupted write or crash mid-save; the file contains comments or a JSONC-style format strict JSON.parse rejects; encoding issues (BOM, invalid UTF-8); the file was hand-edited with a syntax mistake.
Common situations: Machine or Trae killed while extensions.json was being rewritten; tooling or a user manually edited the file; another process wrote it in a slightly different format; disk-full corruption.
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.
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Chess.com callback returned malformed JSON for ${url}: ${err
- Ctrip flight API returned invalid JSON
- hf paper returned malformed JSON: ${err?.message ?? err}
- ${label} returned malformed JSON: ${err?.message ?? err}
- mdn search returned malformed JSON: ${err?.message ?? err}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/5979adc34bcaf154.
Report an issue: GitHub.