From b47291264b4d2508e288b4ec122589d3aae7a0e5 Mon Sep 17 00:00:00 2001 From: dataphract Date: Mon, 6 Jun 2022 15:47:52 +0000 Subject: [PATCH] diagnostics: meaningful error when graph node has wrong number of inputs (#4924) # Objective Currently, providing the wrong number of inputs to a render graph node triggers this assertion: ``` thread 'main' panicked at 'assertion failed: `(left == right)` left: `1`, right: `2`', /[redacted]/bevy/crates/bevy_render/src/renderer/graph_runner.rs:164:13 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ``` This does not provide the user any context. ## Solution Add a new `RenderGraphRunnerError` variant to handle this case. The new message looks like this: ``` ERROR bevy_render::renderer: Error running render graph: ERROR bevy_render::renderer: > node (name: 'Some("outline_pass")') has 2 input slots, but was provided 1 values ``` --- ## Changelog ### Changed `RenderGraphRunnerError` now has a new variant, `MismatchedInputCount`. ## Migration Guide Exhaustive matches on `RenderGraphRunnerError` will need to add a branch to handle the new `MismatchedInputCount` variant. --- crates/bevy_render/src/renderer/graph_runner.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/bevy_render/src/renderer/graph_runner.rs b/crates/bevy_render/src/renderer/graph_runner.rs index 12d6384d20ace..3ed1b0e971fd5 100644 --- a/crates/bevy_render/src/renderer/graph_runner.rs +++ b/crates/bevy_render/src/renderer/graph_runner.rs @@ -41,6 +41,14 @@ pub enum RenderGraphRunnerError { expected: SlotType, actual: SlotType, }, + #[error( + "node (name: '{node_name:?}') has {slot_count} input slots, but was provided {value_count} values" + )] + MismatchedInputCount { + node_name: Option>, + slot_count: usize, + value_count: usize, + }, } impl RenderGraphRunner { @@ -161,7 +169,13 @@ impl RenderGraphRunner { .map(|(_, value)| value) .collect(); - assert_eq!(inputs.len(), node_state.input_slots.len()); + if inputs.len() != node_state.input_slots.len() { + return Err(RenderGraphRunnerError::MismatchedInputCount { + node_name: node_state.name.clone(), + slot_count: node_state.input_slots.len(), + value_count: inputs.len(), + }); + } let mut outputs: SmallVec<[Option; 4]> = smallvec![None; node_state.output_slots.len()];