garrytan/gstack · error · Error

Missing value for --shard

Error message

Missing value for --shard

What it means

In parseArgs (scripts/test-free-shards.ts:255) the --shard (singular) flag selects a specific shard index and must be followed by a value token. Same shape as --shards: a missing next token throws. The value is Number.parseInt'd into shardIndex.

Source

Thrown at scripts/test-free-shards.ts:255

  let windowsOnly = false;
  let shardCount = DEFAULT_SHARD_COUNT;
  let shardIndex: number | null = null;

  for (let index = 0; index < argv.length; index += 1) {
    const arg = argv[index];
    if (arg === '--dry-run') { dryRun = true; continue; }
    if (arg === '--list') { listOnly = true; continue; }
    if (arg === '--windows-only') { windowsOnly = true; continue; }
    if (arg === '--shards') {
      const value = argv[index + 1];
      if (!value) throw new Error('Missing value for --shards');
      shardCount = Number.parseInt(value, 10);
      index += 1;
      continue;
    }
    if (arg === '--shard') {
      const value = argv[index + 1];
      if (!value) throw new Error('Missing value for --shard');
      shardIndex = Number.parseInt(value, 10);
      index += 1;
      continue;
    }
    throw new Error(`Unknown argument: ${arg}`);
  }

  return { dryRun, listOnly, windowsOnly, shardCount, shardIndex };
}

function formatShardSummary(shards: string[][]): string[] {
  return shards.map((files, index) => {
    const preview = files.slice(0, 3).join(', ');
    const suffix = files.length > 3 ? ', ...' : '';
    return `Shard ${index + 1}/${shards.length}: ${files.length} files${preview ? ` -> ${preview}${suffix}` : ''}`;
  });
}

View on GitHub (pinned to 94993f7401)

Solutions

  1. Append the index: `--shard 0`
  2. Default the env var (e.g. `--shard ${i:-0}`)
  3. Skip the flag when no specific shard is needed (run all shards)

Example fix

# before
test-free-shards --shard
# after
test-free-shards --shard 0
Defensive patterns

Strategy: validation

Validate before calling

const i = argv.indexOf('--shard');
if (i !== -1 && argv[i + 1] == null) {
  console.error('Missing value for --shard');
  process.exit(2);
}

Prevention

When it happens

Trigger: Trailing `--shard` with no value. Matrix CI passing `--shard $i` where i is empty on the first iteration.

Common situations: CI matrix variable unset on certain index values. Shell parameter expansion producing nothing.

Related errors


AI-assisted analysis of garrytan/gstack@94993f7401 (2026-08-12). Data as JSON: /api/errors/523c948c816de5eb. Report an issue: GitHub.