affaan-m/ECC · error
Invalid JSON in
Error message
Invalid JSON in ${label}: ${error.message} What it means
readJson reads a file synchronously and JSON.parses it; any parse failure (or read error surfaced as such) is rethrown with a labeled message identifying which config file is invalid. The original error message (with position info) is appended for diagnosis.
Solutions
- Open the config file named in the error and fix the JSON syntax at the reported position.
- Validate with `node -e "JSON.parse(require('fs').readFileSync(process.argv[1],'utf8'))" <config.json>`.
- Restore the file from version control or reinstall if the file is corrupted.
- Convert JSONC (comments) to strict JSON before use.
Example fix
// before (config.json)
{ "name": "ecc", /* main */ }
// after
{ "name": "ecc" } Defensive patterns
Strategy: try-catch
Validate before calling
try { JSON.parse(fs.readFileSync(configPath, 'utf8')); } catch (e) { throw new Error(`${configPath} is not valid JSON: ${e.message}`); } Type guard
function isValidJsonFile(p) { try { JSON.parse(fs.readFileSync(p, 'utf8')); return true; } catch { return false; } } Try / catch
try {
const config = loadInstallConfig(configPath);
} catch (error) {
if (error.message.startsWith('Invalid JSON in')) {
console.error(`Fix ${configPath}:`, error.message);
return;
}
throw error;
} Prevention
- Lint install config JSON in CI before running install scripts
- Keep config files in git to recover from corruption
- Strip comments/trailing commas (use strict JSON, not JSONC)
- Validate after any manual edit to the config file
When it happens
Trigger: Calling resolveInstallConfigPath-adjacent config loaders (schema/raw) when the install config JSON file contains malformed JSON — trailing commas, comments, truncation, or encoding problems.
Common situations: A hand-edited install config, a corrupted download/checkout, an editor saving JSONC with comments, or a partially written file from an interrupted process.
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
- Cannot merge ECC configuration into invalid JSON at
- Failed to parse
- Invalid JSON in at
- candidate configuration exceeds 1 MiB
- Cannot merge ECC configuration at
AI-assisted analysis of affaan-m/ECC@8321021c54 (2026-09-16).
Data as JSON: /api/errors/0fb41fed306053d4.
Report an issue: GitHub.
Appendix: source
Thrown at scripts/lib/install/config.js:15
'use strict';
const fs = require('fs');
const path = require('path');
const DEFAULT_INSTALL_CONFIG = 'ecc-install.json';
const CONFIG_SCHEMA_PATH = path.join(__dirname, '..', '..', '..', 'schemas', 'ecc-install-config.schema.json');
let cachedValidator = null;
function readJson(filePath, label) {
try {
return JSON.parse(fs.readFileSync(filePath, 'utf8'));
} catch (error) {
throw new Error(`Invalid JSON in ${label}: ${error.message}`);
}
}
function getValidator() {
if (cachedValidator) {
return cachedValidator;
}
// ajv is required lazily so scripts that never load an install config (the
// common case, e.g. `--list-profiles`) don't need it on the require path.
const Ajv = require('ajv');
const schema = readJson(CONFIG_SCHEMA_PATH, 'ecc-install-config.schema.json');
const ajv = new Ajv({ allErrors: true });
cachedValidator = ajv.compile(schema);
return cachedValidator;
}
function dedupeStrings(values) {View on GitHub (pinned to 8321021c54)