{"record":{"id":"0fb41fed306053d4","repo":"affaan-m/ECC","slug":"invalid-json-in-label-error-message","errorCode":null,"errorMessage":"Invalid JSON in ${label}: ${error.message}","messagePattern":"Invalid JSON in (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/lib/install/config.js","lineNumber":15,"sourceCode":"'use strict';\n\nconst fs = require('fs');\nconst path = require('path');\n\nconst DEFAULT_INSTALL_CONFIG = 'ecc-install.json';\nconst CONFIG_SCHEMA_PATH = path.join(__dirname, '..', '..', '..', 'schemas', 'ecc-install-config.schema.json');\n\nlet cachedValidator = null;\n\nfunction readJson(filePath, label) {\n  try {\n    return JSON.parse(fs.readFileSync(filePath, 'utf8'));\n  } catch (error) {\n    throw new Error(`Invalid JSON in ${label}: ${error.message}`);\n  }\n}\n\nfunction getValidator() {\n  if (cachedValidator) {\n    return cachedValidator;\n  }\n\n  // ajv is required lazily so scripts that never load an install config (the\n  // common case, e.g. `--list-profiles`) don't need it on the require path.\n  const Ajv = require('ajv');\n  const schema = readJson(CONFIG_SCHEMA_PATH, 'ecc-install-config.schema.json');\n  const ajv = new Ajv({ allErrors: true });\n  cachedValidator = ajv.compile(schema);\n  return cachedValidator;\n}\n\nfunction dedupeStrings(values) {","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/install/config.js#L1-L33","documentation":"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.","triggerScenarios":"Calling resolveInstallConfigPath-adjacent config loaders (schema/raw) when the install config JSON file contains malformed JSON — trailing commas, comments, truncation, or encoding problems.","commonSituations":"A hand-edited install config, a corrupted download/checkout, an editor saving JSONC with comments, or a partially written file from an interrupted process.","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."],"exampleFix":"// before (config.json)\n{ \"name\": \"ecc\", /* main */ }\n// after\n{ \"name\": \"ecc\" }","handlingStrategy":"try-catch","validationCode":"try { JSON.parse(fs.readFileSync(configPath, 'utf8')); } catch (e) { throw new Error(`${configPath} is not valid JSON: ${e.message}`); }","typeGuard":"function isValidJsonFile(p) { try { JSON.parse(fs.readFileSync(p, 'utf8')); return true; } catch { return false; } }","tryCatchPattern":"try {\n  const config = loadInstallConfig(configPath);\n} catch (error) {\n  if (error.message.startsWith('Invalid JSON in')) {\n    console.error(`Fix ${configPath}:`, error.message);\n    return;\n  }\n  throw error;\n}","preventionTips":["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"],"tags":["json","config","parse-error"],"backgroundTag":"json-parse-error","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}