{"record":{"id":"b982e590ef1bf983","repo":"Egonex-AI/Understand-Anything","slug":"invalid-input-must-contain-projectroot-and-files","errorCode":null,"errorMessage":"Invalid input: must contain projectRoot and files array","messagePattern":"Invalid input: must contain projectRoot and files array","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"understand-anything-plugin/skills/understand/extract-import-map.mjs","lineNumber":1812,"sourceCode":"  return [];\n}\n\n// ---------------------------------------------------------------------------\n// Main\n// ---------------------------------------------------------------------------\nasync function main() {\n  const [,, inputPath, outputPath] = process.argv;\n  if (!inputPath || !outputPath) {\n    process.stderr.write('Usage: node extract-import-map.mjs <input.json> <output.json>\\n');\n    process.exit(1);\n  }\n\n  const inputRaw = readFileSync(inputPath, 'utf-8');\n  const input = JSON.parse(inputRaw);\n  const { projectRoot, files } = input;\n\n  if (!projectRoot || !Array.isArray(files)) {\n    throw new Error('Invalid input: must contain projectRoot and files array');\n  }\n\n  // Create tree-sitter plugin with all configs that have WASM grammars.\n  //\n  // WHY graceful init: the most likely real-world failure mode is the WASM\n  // loader failing to locate or fetch the grammar binaries (cache eviction,\n  // restricted sandboxes, transient FS issues). When that happens, we still\n  // want the script to complete — producing an empty importMap for every\n  // code file — rather than crashing the whole project-scanner pipeline.\n  // The structural graph will lose import edges, but all OTHER analysis\n  // (file inventory, exports inferred from filenames, etc.) keeps working.\n  let registry = null;\n  let treeSitterReady = false;\n  try {\n    const tsConfigs = builtinLanguageConfigs.filter(c => c.treeSitter);\n    const tsPlugin = new TreeSitterPlugin(tsConfigs);\n    await tsPlugin.init();\n    registry = new PluginRegistry();","sourceCodeStart":1794,"sourceCodeEnd":1830,"githubUrl":"https://github.com/Egonex-AI/Understand-Anything/blob/32944829e7a63a9fa9c55d811d7f98a9530c6a6a/understand-anything-plugin/skills/understand/extract-import-map.mjs#L1794-L1830","documentation":"Thrown by extract-import-map.mjs main() after parsing its input JSON. It requires projectRoot (truthy) and files (an Array); batchImportData is optional. Failing this aborts before the graceful tree-sitter init block, because there is nothing to scan without a file list.","triggerScenarios":"process.argv lacks inputPath/outputPath (caught by the earlier usage exit). This throw fires when the parsed input JSON has no projectRoot or files is not an array — e.g. the field was named fileNames, the input was an empty object, or files was passed as a comma-separated string.","commonSituations":"The project-scanner / benchmark driver wrote the input with a different field name (files vs sourceFilePaths — note the sibling script uses sourceFilePaths; this one uses files). Truncated/empty input JSON. A producer that omits projectRoot when cwd is implied. Version drift between the producer and this worker's schema.","solutions":["Open the input JSON at the inputPath argument and confirm { projectRoot: <string>, files: [<string>, ...] }.","If the producer used sourceFilePaths, rename it to files for this worker (or update the producer to emit both / the correct name).","Ensure projectRoot is a non-empty string and files is an actual array (not a string, not an object).","Re-run the upstream stage that emits import-input.json so it matches the current worker schema."],"exampleFix":"// before — mismatched field name\n{ \"projectRoot\": \"./repo\", \"sourceFilePaths\": [\"./a.ts\"] }\n\n// after — this worker expects `files`\n{ \"projectRoot\": \"./repo\", \"files\": [\"./a.ts\"] }","handlingStrategy":"validation","validationCode":"import { readFileSync } from 'node:fs';\nfunction readImportMapInput(inputPath) {\n  const raw = JSON.parse(readFileSync(inputPath, 'utf-8'));\n  if (!raw.projectRoot) throw new Error('input missing projectRoot');\n  if (!Array.isArray(raw.files)) throw new Error('files must be an array');\n  return raw;\n}","typeGuard":"function isImportMapInput(v) {\n  return v !== null && typeof v === 'object'\n    && typeof v.projectRoot === 'string' && v.projectRoot.length > 0\n    && Array.isArray(v.files)\n    && v.files.every((f) => typeof f === 'string');\n}","tryCatchPattern":"try {\n  const input = readImportMapInput(inputPath);\n} catch (e) {\n  process.stderr.write(`extract-import-map input invalid: ${e.message}\\n`);\n  process.exit(1);\n}","preventionTips":["This worker expects `files` (not sourceFilePaths, not batchFiles) — match the exact field name.","Producers should write the input via the same version of the worker that consumes it.","Validate projectRoot is a non-empty string and files is an array before invoking."],"tags":["skill","import-map","input-validation","cli","json-input"],"backgroundTag":null,"analyzedSha":"32944829e7a63a9fa9c55d811d7f98a9530c6a6a","analyzedAt":"2026-08-12T10:25:44.261Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}