Skip to content

Commit cba9bcc

Browse files
committed
improve error messages for render graph runner (#3930)
# Objective Currently, errors in the render graph runner are exposed via a `Result::unwrap()` panic message, which dumps the debug representation of the error. ## Solution This PR updates `render_system` to log the chain of errors, followed by an explicit panic: ``` ERROR bevy_render::renderer: Error running render graph: ERROR bevy_render::renderer: > encountered an error when running a sub-graph ERROR bevy_render::renderer: > tried to pass inputs to sub-graph "outline_graph", which has no input slots thread 'main' panicked at 'Error running render graph: encountered an error when running a sub-graph', /[redacted]/bevy/crates/bevy_render/src/renderer/mod.rs:44:9 ``` Some errors' `Display` impls (via `thiserror`) have also been updated to provide more detail about the cause of the error.
1 parent 159fe52 commit cba9bcc

File tree

3 files changed

+40
-12
lines changed

3 files changed

+40
-12
lines changed

crates/bevy_render/src/render_graph/context.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,11 @@ impl<'a> RenderGraphContext<'a> {
207207

208208
#[derive(Error, Debug, Eq, PartialEq)]
209209
pub enum RunSubGraphError {
210-
#[error("tried to run a non-existent sub-graph")]
210+
#[error("attempted to run sub-graph `{0}`, but it does not exist")]
211211
MissingSubGraph(Cow<'static, str>),
212-
#[error("passed in inputs, but this sub-graph doesn't have any")]
212+
#[error("attempted to pass inputs to sub-graph `{0}`, which has no input slots")]
213213
SubGraphHasNoInputs(Cow<'static, str>),
214-
#[error("sub graph (name: '{graph_name:?}') could not be run because slot '{slot_name}' at index {slot_index} has no value")]
214+
#[error("sub graph (name: `{graph_name:?}`) could not be run because slot `{slot_name}` at index {slot_index} has no value")]
215215
MissingInput {
216216
slot_index: usize,
217217
slot_name: Cow<'static, str>,
@@ -229,9 +229,9 @@ pub enum RunSubGraphError {
229229

230230
#[derive(Error, Debug, Eq, PartialEq)]
231231
pub enum OutputSlotError {
232-
#[error("slot does not exist")]
232+
#[error("output slot `{0:?}` does not exist")]
233233
InvalidSlot(SlotLabel),
234-
#[error("attempted to assign the wrong type to slot")]
234+
#[error("attempted to output a value of type `{actual}` to output slot `{label:?}`, which has type `{expected}`")]
235235
MismatchedSlotType {
236236
label: SlotLabel,
237237
expected: SlotType,
@@ -241,9 +241,9 @@ pub enum OutputSlotError {
241241

242242
#[derive(Error, Debug, Eq, PartialEq)]
243243
pub enum InputSlotError {
244-
#[error("slot does not exist")]
244+
#[error("input slot `{0:?}` does not exist")]
245245
InvalidSlot(SlotLabel),
246-
#[error("attempted to retrieve the wrong type from input slot")]
246+
#[error("attempted to retrieve a value of type `{actual}` from input slot `{label:?}`, which has type `{expected}`")]
247247
MismatchedSlotType {
248248
label: SlotLabel,
249249
expected: SlotType,

crates/bevy_render/src/render_graph/node_slot.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bevy_ecs::entity::Entity;
2-
use std::borrow::Cow;
2+
use std::{borrow::Cow, fmt};
33

44
use crate::render_resource::{Buffer, Sampler, TextureView};
55

@@ -74,6 +74,19 @@ pub enum SlotType {
7474
Entity,
7575
}
7676

77+
impl fmt::Display for SlotType {
78+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
79+
let s = match self {
80+
SlotType::Buffer => "Buffer",
81+
SlotType::TextureView => "TextureView",
82+
SlotType::Sampler => "Sampler",
83+
SlotType::Entity => "Entity",
84+
};
85+
86+
f.write_str(s)
87+
}
88+
}
89+
7790
/// A [`SlotLabel`] is used to reference a slot by either its name or index
7891
/// inside the [`RenderGraph`](super::RenderGraph).
7992
#[derive(Debug, Clone, Eq, PartialEq)]

crates/bevy_render/src/renderer/mod.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
mod graph_runner;
22
mod render_device;
33

4-
use bevy_utils::tracing::{info, info_span};
4+
use bevy_utils::tracing::{error, info, info_span};
55
pub use graph_runner::*;
66
pub use render_device::*;
77

@@ -22,13 +22,28 @@ pub fn render_system(world: &mut World) {
2222
let graph = world.resource::<RenderGraph>();
2323
let render_device = world.resource::<RenderDevice>();
2424
let render_queue = world.resource::<RenderQueue>();
25-
RenderGraphRunner::run(
25+
26+
if let Err(e) = RenderGraphRunner::run(
2627
graph,
2728
render_device.clone(), // TODO: is this clone really necessary?
2829
render_queue,
2930
world,
30-
)
31-
.unwrap();
31+
) {
32+
error!("Error running render graph:");
33+
{
34+
let mut src: &dyn std::error::Error = &e;
35+
loop {
36+
error!("> {}", src);
37+
match src.source() {
38+
Some(s) => src = s,
39+
None => break,
40+
}
41+
}
42+
}
43+
44+
panic!("Error running render graph: {}", e);
45+
}
46+
3247
{
3348
let span = info_span!("present_frames");
3449
let _guard = span.enter();

0 commit comments

Comments
 (0)