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

  1. Open the config file named in the error and fix the JSON syntax at the reported position.
  2. Validate with `node -e "JSON.parse(require('fs').readFileSync(process.argv[1],'utf8'))" <config.json>`.
  3. Restore the file from version control or reinstall if the file is corrupted.
  4. 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

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.

Related errors


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)