From bb1538a13926327ad7996a1e7ba9c12c5784ac9a Mon Sep 17 00:00:00 2001 From: Kevin King <4kevinking@gmail.com> Date: Fri, 4 Feb 2022 02:26:18 +0000 Subject: [PATCH] improve error message for attempting to add systems using add_system_to_stage (#3287) # Objective Fixes #3250 ## Solution Since this panic occurs in bevy_ecs, and StartupStage is part of bevy_app, we really only have access to the Debug string of the `stage_label` parameter. This led me to the hacky solution of comparing the debug output of the label the user provides with the known variants of StartupStage. An alternative would be to do this error handling further up in bevy_app, where we can access StartupStage's typeid, but I don't think it is worth having a panic in 2 places (_ecs, and _app). --- crates/bevy_app/src/app.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/bevy_app/src/app.rs b/crates/bevy_app/src/app.rs index adf7bcf239a9c..5bf9805429693 100644 --- a/crates/bevy_app/src/app.rs +++ b/crates/bevy_app/src/app.rs @@ -370,6 +370,10 @@ impl App { stage_label: impl StageLabel, system: impl IntoSystemDescriptor, ) -> &mut Self { + use std::any::TypeId; + if stage_label.type_id() == TypeId::of::() { + panic!("add systems to a startup stage using App::add_startup_system_to_stage"); + } self.schedule.add_system_to_stage(stage_label, system); self } @@ -400,6 +404,10 @@ impl App { stage_label: impl StageLabel, system_set: SystemSet, ) -> &mut Self { + use std::any::TypeId; + if stage_label.type_id() == TypeId::of::() { + panic!("add system sets to a startup stage using App::add_startup_system_set_to_stage"); + } self.schedule .add_system_set_to_stage(stage_label, system_set); self