{"record":{"id":"846addeb0e446908","repo":"garrytan/gstack","slug":"missing-value-for-shards","errorCode":null,"errorMessage":"Missing value for --shards","messagePattern":"Missing value for --shards","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"scripts/test-free-shards.ts","lineNumber":248,"sourceCode":"  shardCount: number;\n  shardIndex: number | null;\n};\n\nfunction parseCliOptions(argv: string[]): CliOptions {\n  let dryRun = false;\n  let listOnly = false;\n  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[] {","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/garrytan/gstack/blob/94993f74012782fd94416dd44b8314f6363a13a4/scripts/test-free-shards.ts#L230-L266","documentation":"In parseArgs (scripts/test-free-shards.ts:248) the --shards flag must be followed by a value token. If --shards is the last argv token or the next token is missing, it throws. The parsed value is then Number.parseInt'd into shardCount.","triggerScenarios":"Running `test-free-shards --shards` at the end of the command. Shell variable feeding the value being unset and producing no token.","commonSituations":"Conditionally appending `--shards $N` in a script where N is unset. Trailing flag from a generated argv array.","solutions":["Append the value: `--shards 4`","Use a shell default: `--shards ${N:-4}`","Skip the flag entirely to keep DEFAULT_SHARD_COUNT"],"exampleFix":"# before\ntest-free-shards --shards\n# after\ntest-free-shards --shards 4","handlingStrategy":"validation","validationCode":"const i = argv.indexOf('--shards');\nif (i !== -1 && argv[i + 1] == null) {\n  console.error('Missing value for --shards');\n  process.exit(2);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Quote CLI args sourced from environment variables","Use `set -u` in bash to catch unset variables before they reach the CLI","Provide a shell default: `--shards ${N:-4}`"],"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"}