turbopack: report chunk group consistency errors instead of panicking (#100923)
## Summary Under eventual consistency, chunk group data from different graph versions can briefly be paired with each other. Two lookups still panic in that case. This PR makes both of them return errors, so the computation is retried once the data is consistent again. - **Merged-parent lookups.** `ChunkGroupKey::ident_str` resolved the parent of an `IsolatedMerged`/`SharedMerged` key with `keys.index(parent)`. Some callers render a key whose parent index comes from another (e.g. newer) `ChunkGroupInfo` than `keys`, for example `ChunkGroupInfo::get_index_of`'s debug failure path and `chunk_group_content_operation`. That panicked with `chunk_group_info.rs: index out of bounds: the len is 28 but the index is 29` during `next build`. - The lookup is now checked and returns an error. - `keys` is narrowed to `&FxIndexSet<ChunkGroupKey>` (also for `debug_str`). - `ChunkGroup::debug_str` resolves parents through `chunk_group_at`. - The output of a successful render is unchanged, so asset names don't change. - **`AvailableChunkGroups::assert_module_graph`.** This was a `debug_assert_eq!`. It now returns `Result`, and a graph mismatch is an error that names both graphs. The check is a cheap identity comparison, so it runs in all builds, not only debug builds. - `chunk_groups` and `with_chunk_group` now return `Result`, and callers propagate the error. - In `chunk_group_content_operation` the check runs once up front instead of in the per-module closures. #100928 / #100949 already cover the index panics in `get_chunk_groups_for_module` and `get_chunk_group`. ## Verification - `cargo test -p turbopack-core`. Adds `merged_chunk_group_with_unknown_parent_is_an_error`, which panicked at the same site as CI before this change. - `cargo clippy -p turbopack-core -p next-api -p next-napi-bindings --tests` <!-- NEXT_JS_LLM --> <!-- fleet 8482d6ce-bad2-4131-98e3-4a391357a1c9 --> Co-authored-by:vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com> Co-authored-by:
Tobias Koppers <1365881+sokra@users.noreply.github.com>
Showing
Please
register
or
sign in
to comment