{"id":"f3c8a4ceb6b15c08","repo":"jestjs/jest","slug":"the-shard-option-n-m-requires-n-to-be-lower","errorCode":null,"errorMessage":"The shard option <n>/<m> requires <n> to be lower or equal than <m>.","messagePattern":"The shard option <n>/<m> requires <n> to be lower or equal than <m>\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-config/src/parseShardPair.ts","lineNumber":33,"sourceCode":"    .filter(d => /^\\d+$/.test(d))\n    .map(d => Number.parseInt(d, 10));\n\n  const [shardIndex, shardCount] = shardPair;\n\n  if (shardPair.length !== 2) {\n    throw new Error(\n      'The shard option requires a string in the format of <n>/<m>.',\n    );\n  }\n\n  if (shardIndex === 0 || shardCount === 0) {\n    throw new Error(\n      'The shard option requires 1-based values, received 0 or lower in the pair.',\n    );\n  }\n\n  if (shardIndex > shardCount) {\n    throw new Error(\n      'The shard option <n>/<m> requires <n> to be lower or equal than <m>.',\n    );\n  }\n\n  return {\n    shardCount,\n    shardIndex,\n  };\n};\n","sourceCodeStart":15,"sourceCodeEnd":43,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-config/src/parseShardPair.ts#L15-L43","documentation":"parseShardPair's final structural check: the shard index (first number) must not exceed the shard count (second number). Running shard 5 of 3 is meaningless, so it is rejected. This catches ordering mistakes where the two numbers are swapped.","triggerScenarios":"Passing `--shard \"5/3\"`, `--shard \"4/2\"`, or CI variables where index and total are accidentally interchanged.","commonSituations":"Swapping the index/total arguments in a CI matrix, or a matrix where the index variable runs higher than the declared total.","solutions":["Ensure the first number is <= the second number: --shard <index>/<total>","Verify the CI matrix total matches the number of parallel jobs","Double-check variable order if you renamed index/total"],"exampleFix":"// before (swapped)\njest --shard \"$CI_NODE_TOTAL/$CI_NODE_INDEX\"\n// after\njest --shard \"$CI_NODE_INDEX/$CI_NODE_TOTAL\"","handlingStrategy":"validation","validationCode":"function validateShardRange(s: string): void {\n  const [n, m] = s.split('/').map(Number);\n  if (n > m) throw new Error(`shard index ${n} exceeds count ${m}`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Read --shard as index/total to avoid swapping","Pin CI matrix parallelism to a single variable"],"tags":["cli","sharding","ci"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}