Egonex-AI/Understand-Anything · error

Usage: node prepare-incremental.mjs

Error message

Usage: node prepare-incremental.mjs <projectRoot> <baseCommit> [--exclude <patterns>]

What it means

parseArgs requires exactly two positional arguments: the project root and the base commit. Any other count (too few or too many) triggers this usage error, which documents the full accepted command line.

Solutions

  1. Supply exactly two positionals: node prepare-incremental.mjs <projectRoot> <baseCommit>
  2. Quote the project root if it contains spaces: node prepare-incremental.mjs "/path/with spaces" HEAD
  3. Use a valid base commit (SHA, branch, or tag) as the second argument
  4. Confirm the working directory/CI step invokes the script with the intended arguments

Example fix

// before
node prepare-incremental.mjs .
// after
node prepare-incremental.mjs . HEAD~1
Defensive patterns

Strategy: validation

Validate before calling

const positionals = process.argv.slice(2).filter(a => !a.startsWith('--'));
if (positionals.length !== 2) {
  console.error('Usage: node prepare-incremental.mjs <projectRoot> <baseCommit> [--exclude <patterns>]');
  process.exit(1);
}

Try / catch

try {
  const parsed = parseArgs(argv);
} catch (err) {
  if (err.message.startsWith('Usage:')) {
    console.error(err.message);
    process.exit(1);
  }
  throw err;
}

Prevention

When it happens

Trigger: Running the script with zero or one positional argument, or with extra stray positional arguments (e.g. unquoted paths with spaces adding a third positional).

Common situations: Forgetting the baseCommit argument, running the script from a README example with placeholders, or shell word-splitting an unquoted project path containing spaces into multiple positionals.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of Egonex-AI/Understand-Anything@07edf82a04 (2026-09-07). Data as JSON: /api/errors/bd68c76f6b689dc7. Report an issue: GitHub.

Appendix: source

Thrown at understand-anything-plugin/skills/understand/prepare-incremental.mjs:469

}

function parseArgs(argv) {
  const positionals = [];
  const excludePatterns = [];
  for (let i = 0; i < argv.length; i++) {
    const arg = argv[i];
    if (arg === '--exclude') {
      const value = argv[++i];
      if (!value || value.startsWith('--')) throw new Error('--exclude requires patterns');
      excludePatterns.push(...value.split(',').map(item => item.trim()).filter(Boolean));
    } else if (arg.startsWith('--')) {
      throw new Error(`Unknown option: ${arg}`);
    } else {
      positionals.push(arg);
    }
  }
  if (positionals.length !== 2) {
    throw new Error(
      'Usage: node prepare-incremental.mjs <projectRoot> <baseCommit> [--exclude <patterns>]',
    );
  }
  return { projectRoot: positionals[0], baseCommit: positionals[1], excludePatterns };
}

async function main() {
  const args = parseArgs(process.argv.slice(2));
  const projectRoot = realpathSync(args.projectRoot);
  const uaDir = resolveUaDir(projectRoot);
  const intermediateDir = join(uaDir, 'intermediate');
  mkdirSync(intermediateDir, { recursive: true });

  const baseCommit = resolveCommit(projectRoot, args.baseCommit);
  const headCommit = resolveCommit(projectRoot, 'HEAD');
  const dirtyPaths = relevantWorktreeChanges(projectRoot, args.excludePatterns);
  if (dirtyPaths.length > 0) {
    const preview = dirtyPaths.slice(0, 10).join(', ');

View on GitHub (pinned to 07edf82a04)