{"record":{"id":"d7a512f0bde721b5","repo":"vercel-labs/agent-skills","slug":"could-not-read-label-json-at-path-err-mes","errorCode":null,"errorMessage":"Could not read ${label} JSON at ${path}: ${err.message}","messagePattern":"Could not read (.+?) JSON at (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"skills/vercel-optimize/scripts/merge-signals.mjs","lineNumber":160,"sourceCode":"function parseArgs(argv) {\n  const out = { positional: [], force: false };\n  for (let i = 0; i < argv.length; i++) {\n    const a = argv[i];\n    if (a === '--out') out.outPath = argv[++i];\n    else if (a.startsWith('--out=')) out.outPath = a.slice('--out='.length);\n    else if (a === '--force') out.force = true;\n    else out.positional.push(a);\n  }\n  out.signalsPath = out.positional[0];\n  out.codebasePath = out.positional[1];\n  return out;\n}\n\nasync function readJson(path, label) {\n  try {\n    return JSON.parse(await readFile(path, 'utf-8'));\n  } catch (err) {\n    throw new Error(`Could not read ${label} JSON at ${path}: ${err.message}`);\n  }\n}\n\nfunction assertObject(value, label) {\n  if (!value || typeof value !== 'object' || Array.isArray(value)) {\n    throw new Error(`${label} must be a JSON object.`);\n  }\n}\n\nasync function writeOutput(path, body, { force }) {\n  if (!force && await exists(path)) {\n    throw new Error(`output file already exists: ${path}. Use a fresh run directory or pass --force to overwrite.`);\n  }\n  await mkdir(dirname(path), { recursive: true });\n  await writeFile(path, body);\n}\n\nasync function exists(path) {","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/vercel-labs/agent-skills/blob/b8caa260a420a73042e35521de4b5c8baf6446cc/skills/vercel-optimize/scripts/merge-signals.mjs#L142-L178","documentation":"Thrown by readJson() when either readFile or JSON.parse throws for the given path/label. It wraps the underlying error message, so the detail reveals whether the file was missing (ENOENT), unreadable (permissions), or present but not valid JSON (SyntaxError). This is the single chokepoint for loading both signals.json and codebase.json.","triggerScenarios":"The signals or codebase path does not exist (typo, wrong working directory); the file exists but contains malformed JSON (truncated write, trailing comma, BOM); permission denied on the file.","commonSituations":"Running merge-signals from a different cwd than where outputs were written; a previous collect/scan step crashed mid-write leaving a partial JSON file; path constructed with a wrong variable.","solutions":["Confirm the path exists and is readable: `ls -l <path>` and `node -e 'JSON.parse(require(\"fs\").readFileSync(\"<path>\",\"utf8\"))'`.","If the file is truncated/malformed, rerun the step that produced it (collect-signals or scan-codebase).","Run merge-signals from the directory containing the outputs, or pass absolute paths."],"exampleFix":"// before — readJson surfaces an opaque wrapped error\nthrow new Error(`Could not read ${label} JSON at ${path}: ${err.message}`);\n\n// after — validate existence + parseability with a clear precondition\nimport { readFileSync, existsSync } from 'node:fs';\nfunction assertReadableJson(path, label) {\n  if (!existsSync(path)) throw new Error(`${label} not found at ${path}`);\n  try { JSON.parse(readFileSync(path, 'utf-8')); }\n  catch (e) { throw new Error(`${label} at ${path} is not valid JSON: ${e.message}`); }\n}","handlingStrategy":"try-catch","validationCode":"import { existsSync } from 'node:fs';\nimport { readFileSync } from 'node:fs';\nfunction assertJsonReadable(path, label) {\n  if (!existsSync(path)) throw new Error(`${label} not found at ${path}`);\n  try { JSON.parse(readFileSync(path, 'utf-8')); }\n  catch (e) { throw new Error(`${label} at ${path} is not valid JSON: ${e.message}`); }\n}\nassertJsonReadable(signalsPath, 'signals');","typeGuard":null,"tryCatchPattern":"let parsed;\ntry {\n  parsed = await readJson(path, label);\n} catch (err) {\n  if (err.message.startsWith(`Could not read ${label}`)) {\n    // distinguish missing vs malformed from err.message, then rerun producer or fix path\n    throw new Error(`Cannot load ${label}; fix the path or regenerate the file.`);\n  }\n  throw err;\n}","preventionTips":["Run merge-signals from the directory containing the outputs, or use absolute paths.","Regenerate truncated/partial JSON by rerunning collect-signals/scan-codebase.","Assert files exist and parse before invoking merge."],"tags":["filesystem","parsing","io","vercel"],"backgroundTag":null,"analyzedSha":"b8caa260a420a73042e35521de4b5c8baf6446cc","analyzedAt":"2026-08-13T06:03:29.508Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}