{"record":{"id":"bda414a353367c2e","repo":"affaan-m/ECC","slug":"failed-to-parse-label-at-filepath-error-m-bda414","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-targets/kimi-project.js","lineNumber":15,"sourceCode":"const fs = require('fs');\nconst path = require('path');\n\nconst {\n  createInstallTargetAdapter,\n  createManagedOperation,\n  isForeignPlatformPath,\n} = require('./helpers');\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 createMcpMergeOperation(moduleId, repoRoot, targetRoot) {\n  if (!repoRoot) {\n    throw new Error('repoRoot is required to plan Kimi MCP configuration');\n  }\n\n  const sourceRelativePath = '.mcp.json';\n  const sourcePath = path.join(repoRoot, sourceRelativePath);\n  if (!fs.existsSync(sourcePath) || !fs.statSync(sourcePath).isFile()) {\n    return null;","sourceCodeStart":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/scripts/lib/install-targets/kimi-project.js#L1-L33","documentation":"Thrown by readJsonObject in scripts/lib/install-targets/kimi-project.js when JSON.parse fails on the file at filePath. In the Kimi adapter this is called on <repoRoot>/.mcp.json (label is the sourceRelativePath '.mcp.json') inside createMcpMergeOperation, which runs during planOperations whenever a module exposes the 'mcp-configs' path. The original parse error message is inlined so the caller sees the exact JSON syntax problem.","triggerScenarios":"Planning or applying a Kimi install (target: 'kimi') when the source repo's <repoRoot>/.mcp.json exists but is not valid JSON — trailing comma, unterminated string, single quotes, UTF-8 BOM, or a partially written file.","commonSituations":"Hand-edited .mcp.json with a syntax error; another tool mid-write when ECC read it; copy-paste introduced a trailing comma; editor saved with a BOM; JSONL content mistakenly placed in a .json file.","solutions":["Open the file at filePath (the message includes the absolute path) and run node -e \"JSON.parse(require('fs').readFileSync(process.argv[1],'utf8'))\" <filePath> to surface the exact position.","Fix the JSON syntax error (most commonly a trailing comma, missing quote, or single quotes instead of double).","Strip a leading BOM: sed -i '1s/^\\xEF\\xBB\\xBF//' <filePath>.","Validate with jq empty <filePath> or npx jsonlint <filePath> before retrying the install."],"exampleFix":"// before (<repoRoot>/.mcp.json)\n{\n  \"mcpServers\": {\n    \"context7\": { \"command\": \"npx\", },\n  }\n}\n\n// after\n{\n  \"mcpServers\": {\n    \"context7\": { \"command\": \"npx\" }\n  }\n}","handlingStrategy":"try-catch","validationCode":"function preflightJsonObject(filePath) {\n  const raw = require('fs').readFileSync(filePath, 'utf8').replace(/^\\uFEFF/, '');\n  const v = JSON.parse(raw); // throws on bad JSON\n  if (!v || typeof v !== 'object' || Array.isArray(v)) {\n    throw new Error(`${filePath} top level must be a JSON object`);\n  }\n  return v;\n}\n// before planning the Kimi install:\nconst mcpPath = path.join(repoRoot, '.mcp.json');\nif (fs.existsSync(mcpPath)) preflightJsonObject(mcpPath);","typeGuard":"function isJsonObject(value) {\n  return value !== null && typeof value === 'object' && !Array.isArray(value);\n}","tryCatchPattern":"try {\n  planInstallTargetScaffold({ target: 'kimi', modules, repoRoot, projectRoot });\n} catch (err) {\n  if (/Failed to parse .*\\.mcp\\.json/.test(err.message)) {\n    console.error('Source .mcp.json is corrupt. Fix JSON syntax and retry. Detail:', err.message);\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Add a CI step that runs jq empty .mcp.json on every commit.","Lint the file in your editor with a JSON schema.","Configure your editor to write plain UTF-8 (no BOM)."],"tags":["json-parse","kimi","mcp-config","install-target"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}