Skip to content

Commit 394e82f

Browse files
authored
panic on system error (#16979)
# Objective - First step for #16718 - #16589 introduced an api that can only ignore errors, which is risky ## Solution - Panic instead of just ignoring the errors ## Testing - Changed the `fallible_systems` example to return an error ``` Encountered an error in system `fallible_systems::setup`: TooManyVertices { subdivisions: 300, number_of_resulting_points: 906012 } Encountered a panic in system `fallible_systems::setup`! Encountered a panic in system `bevy_app::main_schedule::Main::run_main`! ```
1 parent c03e494 commit 394e82f

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

crates/bevy_ecs/src/schedule/executor/multi_threaded.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -605,11 +605,17 @@ impl ExecutorState {
605605
// access the world data used by the system.
606606
// - `update_archetype_component_access` has been called.
607607
unsafe {
608-
// TODO: implement an error-handling API instead of suppressing a possible failure.
609-
let _ = __rust_begin_short_backtrace::run_unsafe(
608+
// TODO: implement an error-handling API instead of panicking.
609+
if let Err(err) = __rust_begin_short_backtrace::run_unsafe(
610610
system,
611611
context.environment.world_cell,
612-
);
612+
) {
613+
panic!(
614+
"Encountered an error in system `{}`: {:?}",
615+
&*system.name(),
616+
err
617+
);
618+
};
613619
};
614620
}));
615621
context.system_completed(system_index, res, system);
@@ -653,8 +659,14 @@ impl ExecutorState {
653659
// that no other systems currently have access to the world.
654660
let world = unsafe { context.environment.world_cell.world_mut() };
655661
let res = std::panic::catch_unwind(AssertUnwindSafe(|| {
656-
// TODO: implement an error-handling API instead of suppressing a possible failure.
657-
let _ = __rust_begin_short_backtrace::run(system, world);
662+
// TODO: implement an error-handling API instead of panicking.
663+
if let Err(err) = __rust_begin_short_backtrace::run(system, world) {
664+
panic!(
665+
"Encountered an error in system `{}`: {:?}",
666+
&*system.name(),
667+
err
668+
);
669+
};
658670
}));
659671
context.system_completed(system_index, res, system);
660672
};

crates/bevy_ecs/src/schedule/executor/simple.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,14 @@ impl SystemExecutor for SimpleExecutor {
101101
}
102102

103103
let f = AssertUnwindSafe(|| {
104-
// TODO: implement an error-handling API instead of suppressing a possible failure.
105-
let _ = __rust_begin_short_backtrace::run(system, world);
104+
// TODO: implement an error-handling API instead of panicking.
105+
if let Err(err) = __rust_begin_short_backtrace::run(system, world) {
106+
panic!(
107+
"Encountered an error in system `{}`: {:?}",
108+
&*system.name(),
109+
err
110+
);
111+
}
106112
});
107113

108114
#[cfg(feature = "std")]

crates/bevy_ecs/src/schedule/executor/single_threaded.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,29 @@ impl SystemExecutor for SingleThreadedExecutor {
109109

110110
let f = AssertUnwindSafe(|| {
111111
if system.is_exclusive() {
112-
// TODO: implement an error-handling API instead of suppressing a possible failure.
113-
let _ = __rust_begin_short_backtrace::run(system, world);
112+
// TODO: implement an error-handling API instead of panicking.
113+
if let Err(err) = __rust_begin_short_backtrace::run(system, world) {
114+
panic!(
115+
"Encountered an error in system `{}`: {:?}",
116+
&*system.name(),
117+
err
118+
);
119+
}
114120
} else {
115121
// Use run_unsafe to avoid immediately applying deferred buffers
116122
let world = world.as_unsafe_world_cell();
117123
system.update_archetype_component_access(world);
118124
// SAFETY: We have exclusive, single-threaded access to the world and
119125
// update_archetype_component_access is being called immediately before this.
120126
unsafe {
121-
// TODO: implement an error-handling API instead of suppressing a possible failure.
122-
let _ = __rust_begin_short_backtrace::run_unsafe(system, world);
127+
// TODO: implement an error-handling API instead of panicking.
128+
if let Err(err) = __rust_begin_short_backtrace::run_unsafe(system, world) {
129+
panic!(
130+
"Encountered an error in system `{}`: {:?}",
131+
&*system.name(),
132+
err
133+
);
134+
}
123135
};
124136
}
125137
});

crates/bevy_ecs/src/system/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,6 +1766,7 @@ mod tests {
17661766
}
17671767

17681768
#[test]
1769+
#[should_panic]
17691770
fn simple_fallible_system() {
17701771
fn sys() -> Result {
17711772
Err("error")?;

0 commit comments

Comments
 (0)