{"record":{"id":"83c1963c5d929ed3","repo":"affaan-m/ECC","slug":"failed-to-parse-label-at-filepath-error-m-83c196","errorCode":null,"errorMessage":"Failed to parse ${label} at ${filePath}: ${error.message}","messagePattern":"Failed to parse (.+?) at (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"scripts/lib/install-targets/cursor-project.js","lineNumber":28,"sourceCode":"  isForeignPlatformPath,\n} = require('./helpers');\n\nfunction toCursorRuleFileName(fileName, sourceRelativeFile) {\n  if (path.basename(sourceRelativeFile).toLowerCase() === 'readme.md') {\n    return null;\n  }\n\n  return fileName.endsWith('.md')\n    ? `${fileName.slice(0, -3)}.mdc`\n    : fileName;\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 createJsonMergeOperation({ moduleId, repoRoot, sourceRelativePath, destinationPath }) {\n  const sourcePath = path.join(repoRoot, sourceRelativePath);\n  if (!fs.existsSync(sourcePath) || !fs.statSync(sourcePath).isFile()) {\n    return null;\n  }\n\n  return createManagedOperation({\n    kind: 'merge-json',\n    moduleId,","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/scripts/lib/install-targets/cursor-project.js#L10-L46","documentation":"readJsonObject in the Cursor project install target reads a JSON config file (e.g. a Cursor settings or MCP file) and, if the file is missing, unreadable, or not valid JSON, throws with the file path and the underlying parse error. Unlike plain JSON.parse errors, this one tells you which labeled file in the install operation failed.","triggerScenarios":"createJsonMergeOperation for a Cursor project target encounters a destination file that exists but contains invalid JSON (trailing commas, comments, truncation) or cannot be read (permissions/ENOENT on a path expected to exist for merging).","commonSituations":"A Cursor config file was hand-edited with JSONC-style comments; a crashed editor or install left a half-written file; the file was saved with a BOM or encoding issue that breaks JSON.parse.","solutions":["Open the file at the path in the message and fix the JSON syntax error named in error.message","If the file is JSONC (with comments), strip comments or move the config to a plain-JSON location before installing","If unreadable due to permissions, fix chmod/chown on the file","If the file is beyond repair, back it up and delete it so the installer can create a fresh one"],"exampleFix":"// before: .cursor/mcp.json with a trailing comma\n{ \"mcpServers\": { \"context7\": { \"command\": \"npx\", } } }\n// after\n{ \"mcpServers\": { \"context7\": { \"command\": \"npx\" } } }","handlingStrategy":"try-catch","validationCode":"// Pre-flight: ensure the destination file is valid JSON before install\ntry {\n  JSON.parse(fs.readFileSync(cursorConfigPath, 'utf8'));\n} catch (e) {\n  console.error(`Fix ${cursorConfigPath} before installing: ${e.message}`);\n}","typeGuard":"function isPlainObject(v) {\n  return v !== null && typeof v === 'object' && !Array.isArray(v);\n}","tryCatchPattern":"try {\n  runInstallOperation(op);\n} catch (e) {\n  if (/Failed to parse .* at .*:/.test(e.message)) {\n    // point the user at the file path in the message to fix its JSON\n  } else throw e;\n}","preventionTips":["Keep Cursor config files as strict JSON — no comments or trailing commas","Run `node -e \"JSON.parse(...)` on config files after hand edits","Avoid interrupting installs; a partial write leaves unparseable JSON","Editor plugins that lint JSON catch this before the installer does"],"tags":["json","file-io","cursor","install-target"],"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"}