{"record":{"id":"84810658853fb2d3","repo":"affaan-m/ECC","slug":"failed-to-parse-label-at-filepath-error-m-848106","errorCode":null,"errorMessage":"Failed to parse ${label} at ${filePath}: ${error.message}","messagePattern":"Failed to parse (.+?) at (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/lib/install/apply.js","lineNumber":49,"sourceCode":"  }\n  const mappings = [];\n  for (const operation of plan.operations) {\n    if (operation.kind === 'copy-file' && operation.sourceRelativePath) {\n      mappings.push({\n        sourceRel: operation.sourceRelativePath,\n        destRel: path.relative(plan.targetRoot, operation.destinationPath),\n      });\n    }\n  }\n  return buildInstallIndex(mappings);\n}\n\nfunction readJsonObject(filePath, label) {\n  let parsed;\n  try {\n    parsed = JSON.parse(fs.readFileSync(filePath, 'utf8'));\n  } catch (error) {\n    throw new Error(`Failed to parse ${label} at ${filePath}: ${error.message}`);\n  }\n\n  if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {\n    throw new Error(`Invalid ${label} at ${filePath}: expected a JSON object`);\n  }\n\n  return parsed;\n}\n\nfunction stateWithContentDigests(state) {\n  return {\n    ...state,\n    operations: (state.operations || []).map(operation => {\n      if (\n        !operation.destinationPath\n        || !fs.existsSync(operation.destinationPath)\n        || !fs.statSync(operation.destinationPath).isFile()\n      ) {","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/lib/install/apply.js#L31-L67","documentation":"Thrown by readJsonObject in scripts/lib/install/apply.js when JSON.parse fails. This local copy of the helper is used for three labels: 'hooks config' (source hooks.json read in buildResolvedClaudeHooks), 'existing JSON config' (destination .mcp.json / mcp.json being merged into during a merge-json operation), and 'MCP config' (source MCP file on the copy-file-with-filtering path). The original parse error is inlined.","triggerScenarios":"During applyInstallPlan: an existing destination .mcp.json being merged into is corrupt; the source hooks.json is corrupt; a source MCP file that will be copied is corrupt.","commonSituations":"User's existing ~/.claude/.mcp.json has a syntax error from a prior manual edit; a partial write left by a crashed previous run; an editor inserted a BOM or trailing comma.","solutions":["Read the message — it names the exact label and absolute filePath that failed to parse.","Run node -e \"JSON.parse(require('fs').readFileSync(process.argv[1],'utf8'))\" <filePath> to surface the position.","Fix the JSON syntax error, or back up and recreate the file, then re-run the install.","Strip any BOM: sed -i '1s/^\\xEF\\xBB\\xBF//' <filePath>."],"exampleFix":"// before (existing ~/.claude/.mcp.json)\n{\n  \"mcpServers\": {\n    \"x\": { \"command\": \"npx\", }\n  }\n}\n\n// after\n{\n  \"mcpServers\": {\n    \"x\": { \"command\": \"npx\" }\n  }\n}","handlingStrategy":"try-catch","validationCode":"function preflightJson(filePath) {\n  let raw;\n  try { raw = fs.readFileSync(filePath, 'utf8'); } catch (e) { if (e.code !== 'ENOENT') throw e; return; }\n  try { JSON.parse(raw.replace(/^\\uFEFF/, '')); }\n  catch (e) { throw new Error(`Preflight fail ${filePath}: ${e.message}`); }\n}\n['.mcp.json', 'mcp.json', 'hooks/hooks.json'].forEach(f => {\n  preflightJson(path.join(targetRoot, f));\n});","typeGuard":"function isJsonObject(v) {\n  return v !== null && typeof v === 'object' && !Array.isArray(v);\n}","tryCatchPattern":"try {\n  applyInstallPlan(plan);\n} catch (err) {\n  if (/Failed to parse .* at /.test(err.message)) {\n    console.error('Corrupt JSON file — see path in message:', err.message);\n  }\n  throw err;\n}","preventionTips":["Lint every JSON file under the target root before running install.","Back up the existing config before merging.","Strip BOMs from any file written by Windows editors."],"tags":["json-parse","install-apply","mcp-config","hooks"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}