Egonex-AI/Understand-Anything · error · Error

Invalid input: must contain projectRoot and batchFiles array

Error message

Invalid input: must contain projectRoot and batchFiles array

What it means

Thrown by extract-structure.mjs main() after parsing its input JSON. It requires projectRoot (truthy) and batchFiles (an Array); batchImportData is destructured but optional. Aborts before constructing the tree-sitter plugin since without a file list there is nothing to analyze.

Source

Thrown at understand-anything-plugin/skills/understand/extract-structure.mjs:71

const { TreeSitterPlugin, PluginRegistry, builtinLanguageConfigs, registerAllParsers } = core;

// ---------------------------------------------------------------------------
// Main
// ---------------------------------------------------------------------------
async function main() {
  const [,, inputPath, outputPath] = process.argv;
  if (!inputPath || !outputPath) {
    process.stderr.write('Usage: node extract-structure.mjs <input.json> <output.json>\n');
    process.exit(1);
  }

  // Read input
  const inputRaw = readFileSync(inputPath, 'utf-8');
  const input = JSON.parse(inputRaw);
  const { projectRoot, batchFiles, batchImportData } = input;

  if (!projectRoot || !Array.isArray(batchFiles)) {
    throw new Error('Invalid input: must contain projectRoot and batchFiles array');
  }

  // Create tree-sitter plugin with all configs that have WASM grammars
  const tsConfigs = builtinLanguageConfigs.filter(c => c.treeSitter);
  const tsPlugin = new TreeSitterPlugin(tsConfigs);
  await tsPlugin.init();

  // Create registry and register tree-sitter + all non-code parsers
  const registry = new PluginRegistry();
  registry.register(tsPlugin);
  registerAllParsers(registry);

  const results = [];
  const filesSkipped = [];
  const analysisOutcomes = {
    structure: { succeeded: 0, failed: 0 },
    callGraph: { succeeded: 0, failed: 0, skipped: 0 },
  };

View on GitHub (pinned to 32944829e7)

Solutions

  1. Open the input JSON and confirm { projectRoot: <string>, batchFiles: [<string>, ...] }.
  2. If the producer used files, rename to batchFiles for this worker (or fix the producer to emit the correct name).
  3. Ensure projectRoot is a non-empty string and batchFiles is an array.
  4. Re-run the batching stage so it emits batchFiles in the shape this worker expects.

Example fix

// before — wrong field name
{ "projectRoot": "./repo", "files": ["./a.ts"] }

// after — this worker expects `batchFiles`
{ "projectRoot": "./repo", "batchFiles": ["./a.ts"] }
Defensive patterns

Strategy: validation

Validate before calling

import { readFileSync } from 'node:fs';
function readStructureInput(inputPath) {
  const raw = JSON.parse(readFileSync(inputPath, 'utf-8'));
  if (!raw.projectRoot) throw new Error('input missing projectRoot');
  if (!Array.isArray(raw.batchFiles)) throw new Error('batchFiles must be an array');
  return raw;
}

Type guard

function isStructureInput(v) {
  return v !== null && typeof v === 'object'
    && typeof v.projectRoot === 'string' && v.projectRoot.length > 0
    && Array.isArray(v.batchFiles)
    && v.batchFiles.every((f) => typeof f === 'string');
}

Try / catch

try {
  const input = readStructureInput(inputPath);
} catch (e) {
  process.stderr.write(`extract-structure input invalid: ${e.message}\n`);
  process.exit(1);
}

Prevention

When it happens

Trigger: process.argv lacks inputPath/outputPath (caught earlier). This throw fires when the parsed input JSON omits projectRoot, or batchFiles is not an array — e.g. field named files or batch instead of batchFiles, or batchFiles passed as a single string path.

Common situations: The batching driver emitted { files: [...] } instead of { batchFiles: [...] } (note the sibling workers use files / sourceFilePaths; this one is batchFiles). Truncated/empty input. Version drift between the batcher that writes inputs and this worker's schema. Hand-edited input missing projectRoot.

Related errors


AI-assisted analysis of Egonex-AI/Understand-Anything@32944829e7 (2026-08-12). Data as JSON: /api/errors/42bf973b4e28fb95. Report an issue: GitHub.