{"record":{"id":"9b6d87cc59f86d16","repo":"facebook/relay","slug":"total-shard-count-shard-count-must-be-greater-th","errorCode":null,"errorMessage":"Total shard count:{shard_count} must be greater than sum of all shard counts:{typeshard_count} for inidividual types","messagePattern":"Total shard count:(.+?) must be greater than sum of all shard counts:(.+?) for inidividual types","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/crates/schema-print/src/print_schema.rs","lineNumber":88,"sourceCode":"/// Prints shards in sequence. No parallelism is used.\n///\n/// # Arguments\n///\n/// * `schema` - GraphQL SDLSchema\n///\n/// * `shard_count` - Total shard count. Returned vec will have this size.\n///\n/// * `type_shard_count` - To further shard a single type, provide this.\n///   For e.g you might want to shard Query type because its huge.\n///   Sum of all the shard counts provided here must be less than shard_count param.\npub fn print_types_directives_as_shards(\n    schema: &SDLSchema,\n    shard_count: usize,\n    type_shard_count: FnvHashMap<StringKey, usize>,\n) -> Vec<String> {\n    let typeshard_count: usize = type_shard_count.values().sum();\n    if typeshard_count >= shard_count {\n        panic!(\n            \"Total shard count:{shard_count} must be greater than sum of all shard counts:{typeshard_count} for inidividual types\",\n        );\n    }\n    let mut shards: Vec<String> = vec![String::new(); shard_count - typeshard_count];\n\n    // Print directives to first shard\n    shards\n        .first_mut()\n        .unwrap()\n        .push_str(&print_directives(schema));\n\n    let mut type_shards: FnvHashMap<StringKey, Vec<String>> = type_shard_count\n        .iter()\n        .map(|(type_name, count)| (*type_name, vec![String::new(); *count]))\n        .collect();\n    write_types_as_shards(\n        schema,\n        &mut shards,","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/facebook/relay/blob/668b1b85e06261aa3b58dabfc51f8b5524a70955/compiler/crates/schema-print/src/print_schema.rs#L70-L106","documentation":"This is a panic from print_schema's shard-printing logic. When splitting printed schema output across N shards, shards are allocated for the 'leftover' directives only if the total shard count exceeds the sum of per-type shard counts; if typeshard_count >= shard_count, the arithmetic `shard_count - typeshard_count` would underflow (usize), so the function panics instead. It is a caller precondition violation, not a recoverable runtime error.","triggerScenarios":"Calling print_types_directives_as_shards (directly or via transform_fixture) with a shard_count that is less than or equal to the sum of all values in the type_shard_count map, e.g. shard_count=4 with per-type counts {A:2,B:3} (sum 5).","commonSituations":"Test fixture generators (transform_fixture) configured with too few total shards while enumerating many types; scripts that auto-compute per-type shard counts but fix the total shard count too low; typos mixing up 'count' vs 'sum' arguments.","solutions":["Increase the shard_count argument so it is strictly greater than the sum of all type_shard_count values.","Reduce the per-type shard counts in type_shard_count so their sum is below shard_count.","Pre-validate before calling: assert type_shard_count.values().sum::<usize>() < shard_count and produce a clear config error instead of a panic.","Fix the panic message typo ('inidividual' -> 'individual') and message wording in a patch if you maintain this code."],"exampleFix":"// before\nprint_types_directives_as_shards(&schema, 4, type_shard_count); // sum=5 -> panic\n// after\nlet typeshard_sum: usize = type_shard_count.values().sum();\nassert!(typeshard_sum < 8);\nprint_types_directives_as_shards(&schema, 8, type_shard_count);","handlingStrategy":"validation","validationCode":"let typeshard_sum: usize = type_shard_count.values().sum();\nif typeshard_sum >= shard_count {\n    return Err(anyhow!(\n        \"shard_count ({shard_count}) must exceed sum of per-type shards ({typeshard_sum})\"\n    ));\n}","typeGuard":null,"tryCatchPattern":"// Rust: avoid the panic entirely via pre-validation; if wrapping, use catch_unwind only in fixture tools\nlet result = std::panic::catch_unwind(|| print_types_directives_as_shards(&schema, n, map));","preventionTips":["Always compute shard_count as typeshard_sum + desired_leftover_shards.","Add a debug_assert in callers that sum < shard_count.","Convert the panic into a returned Result upstream."],"tags":["rust","panic","sharding","precondition-violation","schema-print"],"backgroundTag":"shard-count-underflow","analyzedSha":"668b1b85e06261aa3b58dabfc51f8b5524a70955","analyzedAt":"2026-09-02T19:57:20.783Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}