Egonex-AI/Understand-Anything · error
Invalid input: must contain projectRoot and files array
Error message
Invalid input: must contain projectRoot and files array
What it means
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.
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.
Example fix
// before — mismatched field name
{ "projectRoot": "./repo", "sourceFilePaths": ["./a.ts"] }
// after — this worker expects `files`
{ "projectRoot": "./repo", "files": ["./a.ts"] } Defensive patterns
Strategy: validation
Validate before calling
import { readFileSync } from 'node:fs';
function readImportMapInput(inputPath) {
const raw = JSON.parse(readFileSync(inputPath, 'utf-8'));
if (!raw.projectRoot) throw new Error('input missing projectRoot');
if (!Array.isArray(raw.files)) throw new Error('files must be an array');
return raw;
} Type guard
function isImportMapInput(v) {
return v !== null && typeof v === 'object'
&& typeof v.projectRoot === 'string' && v.projectRoot.length > 0
&& Array.isArray(v.files)
&& v.files.every((f) => typeof f === 'string');
} Try / catch
try {
const input = readImportMapInput(inputPath);
} catch (e) {
process.stderr.write(`extract-import-map input invalid: ${e.message}\n`);
process.exit(1);
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Invalid input: must contain projectRoot and batchFiles array
- Invalid input: requires
- Invalid input: analysisPaths must be an array when provided
- Invalid input: every analysisPaths entry must be a…
- output file missing after write
AI-assisted analysis of Egonex-AI/Understand-Anything@07edf82a04 (2026-09-07).
Data as JSON: /api/errors/b982e590ef1bf983.
Report an issue: GitHub.
Appendix: source
Thrown at understand-anything-plugin/skills/understand/extract-import-map.mjs:1971
return [];
}
// ---------------------------------------------------------------------------
// Main
// ---------------------------------------------------------------------------
async function main() {
const [,, inputPath, outputPath] = process.argv;
if (!inputPath || !outputPath) {
process.stderr.write('Usage: node extract-import-map.mjs <input.json> <output.json>\n');
process.exit(1);
}
const inputRaw = readFileSync(inputPath, 'utf-8');
const input = JSON.parse(inputRaw);
const { projectRoot, files, analysisPaths } = input;
if (!projectRoot || !Array.isArray(files)) {
throw new Error('Invalid input: must contain projectRoot and files array');
}
const analysisFiles = selectAnalysisFiles(files, analysisPaths);
if (analysisFiles.length === 0) {
const output = {
scriptCompleted: true,
stats: { filesScanned: 0, filesWithImports: 0, totalEdges: 0 },
failures: [],
importMap: {},
};
writeFileSync(outputPath, JSON.stringify(output, null, 2), 'utf-8');
process.stderr.write(
'extract-import-map: filesScanned=0 filesWithImports=0 totalEdges=0\n',
);
return;
}
View on GitHub (pinned to 07edf82a04)