facebook/relay · error
Total shard count:{shard_count} must be greater than sum of
Error message
Total shard count:{shard_count} must be greater than sum of all shard counts:{typeshard_count} for inidividual types What it means
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.
Source
Thrown at compiler/crates/schema-print/src/print_schema.rs:88
/// Prints shards in sequence. No parallelism is used.
///
/// # Arguments
///
/// * `schema` - GraphQL SDLSchema
///
/// * `shard_count` - Total shard count. Returned vec will have this size.
///
/// * `type_shard_count` - To further shard a single type, provide this.
/// For e.g you might want to shard Query type because its huge.
/// Sum of all the shard counts provided here must be less than shard_count param.
pub fn print_types_directives_as_shards(
schema: &SDLSchema,
shard_count: usize,
type_shard_count: FnvHashMap<StringKey, usize>,
) -> Vec<String> {
let typeshard_count: usize = type_shard_count.values().sum();
if typeshard_count >= shard_count {
panic!(
"Total shard count:{shard_count} must be greater than sum of all shard counts:{typeshard_count} for inidividual types",
);
}
let mut shards: Vec<String> = vec![String::new(); shard_count - typeshard_count];
// Print directives to first shard
shards
.first_mut()
.unwrap()
.push_str(&print_directives(schema));
let mut type_shards: FnvHashMap<StringKey, Vec<String>> = type_shard_count
.iter()
.map(|(type_name, count)| (*type_name, vec![String::new(); *count]))
.collect();
write_types_as_shards(
schema,
&mut shards,View on GitHub (pinned to 668b1b85e0)
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.
Example fix
// before print_types_directives_as_shards(&schema, 4, type_shard_count); // sum=5 -> panic // after let typeshard_sum: usize = type_shard_count.values().sum(); assert!(typeshard_sum < 8); print_types_directives_as_shards(&schema, 8, type_shard_count);
Defensive patterns
Strategy: validation
Validate before calling
let typeshard_sum: usize = type_shard_count.values().sum();
if typeshard_sum >= shard_count {
return Err(anyhow!(
"shard_count ({shard_count}) must exceed sum of per-type shards ({typeshard_sum})"
));
} Try / catch
// Rust: avoid the panic entirely via pre-validation; if wrapping, use catch_unwind only in fixture tools let result = std::panic::catch_unwind(|| print_types_directives_as_shards(&schema, n, map));
Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Expected a key
- Unexpected DynamicImport
- Unexpected RelayResolver
- Expected an IR that models a type
- Expected an IR that models a field
AI-assisted analysis of facebook/relay@668b1b85e0 (2026-09-02).
Data as JSON: /api/errors/9b6d87cc59f86d16.
Report an issue: GitHub.