{"record":{"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/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-config/src/parseShardPair.ts#L15-L43","documentation":"Thrown by parseShardPair when the shard index (n) exceeds the shard count (m). Since there are only m shards, requesting shard n>m references a shard that cannot exist. The pair is only valid when 1 <= n <= m.","triggerScenarios":"Passing --shard 5/3, --shard 4/2, or any pair where the first number is greater than the second. Common when the index and total are sourced from different systems that disagree.","commonSituations":"Mismatched CI matrix dimensions (e.g. index sourced from a 5-way job, total from a 3-way job), manual typos, or templating bugs where the two numbers come from different variables.","solutions":["Ensure the shard index never exceeds the shard count","Audit the CI matrix so index and total originate from the same source","Add a preflight check: if [ \"$INDEX\" -gt \"$TOTAL\" ]; then exit 1; fi"],"exampleFix":"# before\njest --shard 5/3\n\n# after\njest --shard 3/5","handlingStrategy":"validation","validationCode":"const [index, count] = shard.split('/').map(Number);\nif (index > count) {\n  throw new Error(`Shard index ${index} exceeds count ${count}`);\n}","typeGuard":"function isValidShardRange(pair: string): boolean {\n  const [i, c] = pair.split('/').map(Number);\n  return i >= 1 && c >= 1 && i <= c;\n}","tryCatchPattern":null,"preventionTips":["Source both shard numbers from the same CI matrix variable set","Add an assertion: test \"$INDEX\" -le \"$TOTAL\"","Use a single env var like SHARD='2/5' parsed in one place"],"tags":["cli","sharding","ci","argument-validation"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}