{"record":{"id":"523c948c816de5eb","repo":"garrytan/gstack","slug":"missing-value-for-shard","errorCode":null,"errorMessage":"Missing value for --shard","messagePattern":"Missing value for --shard","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/test-free-shards.ts","lineNumber":255,"sourceCode":"  let windowsOnly = false;\n  let shardCount = DEFAULT_SHARD_COUNT;\n  let shardIndex: number | null = null;\n\n  for (let index = 0; index < argv.length; index += 1) {\n    const arg = argv[index];\n    if (arg === '--dry-run') { dryRun = true; continue; }\n    if (arg === '--list') { listOnly = true; continue; }\n    if (arg === '--windows-only') { windowsOnly = true; continue; }\n    if (arg === '--shards') {\n      const value = argv[index + 1];\n      if (!value) throw new Error('Missing value for --shards');\n      shardCount = Number.parseInt(value, 10);\n      index += 1;\n      continue;\n    }\n    if (arg === '--shard') {\n      const value = argv[index + 1];\n      if (!value) throw new Error('Missing value for --shard');\n      shardIndex = Number.parseInt(value, 10);\n      index += 1;\n      continue;\n    }\n    throw new Error(`Unknown argument: ${arg}`);\n  }\n\n  return { dryRun, listOnly, windowsOnly, shardCount, shardIndex };\n}\n\nfunction formatShardSummary(shards: string[][]): string[] {\n  return shards.map((files, index) => {\n    const preview = files.slice(0, 3).join(', ');\n    const suffix = files.length > 3 ? ', ...' : '';\n    return `Shard ${index + 1}/${shards.length}: ${files.length} files${preview ? ` -> ${preview}${suffix}` : ''}`;\n  });\n}\n","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/scripts/test-free-shards.ts#L237-L273","documentation":"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.","triggerScenarios":"Trailing `--shard` with no value. Matrix CI passing `--shard $i` where i is empty on the first iteration.","commonSituations":"CI matrix variable unset on certain index values. Shell parameter expansion producing nothing.","solutions":["Append the index: `--shard 0`","Default the env var (e.g. `--shard ${i:-0}`)","Skip the flag when no specific shard is needed (run all shards)"],"exampleFix":"# before\ntest-free-shards --shard\n# after\ntest-free-shards --shard 0","handlingStrategy":"validation","validationCode":"const i = argv.indexOf('--shard');\nif (i !== -1 && argv[i + 1] == null) {\n  console.error('Missing value for --shard');\n  process.exit(2);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate matrix indices before passing them to the CLI","Use shell parameter defaults like `--shard ${i:-0}`","Use `set -u` in bash to detect unset variables"],"tags":["cli","argument-validation","test"],"backgroundTag":null,"analyzedSha":"94993f74012782fd94416dd44b8314f6363a13a4","analyzedAt":"2026-08-12T04:06:23.140Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}