Skip to content

Commit

Permalink
improve error message for attempting to add systems using add_system_…
Browse files Browse the repository at this point in the history
…to_stage

Fixes #3250

Notes:
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).
  • Loading branch information
kcking committed Dec 10, 2021
1 parent cf48132 commit 45fc8c7
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/bevy_ecs/src/schedule/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,14 @@ impl Schedule {
// of the game. Closures inherit generic parameters from their enclosing function.
#[cold]
fn stage_not_found(stage_label: &dyn Debug) -> ! {
if ["PreStartup", "Startup", "PostStartup"]
.contains(&format!("{:?}", stage_label).as_str())
{
panic!(
"Stage '{:?}' does not exist or is not a SystemStage.\nIt looks like you may be trying to add a startup system. Use `add_startup_system_to_stage()` instead of `add_system_to_stage()`.",
stage_label
)
}
panic!(
"Stage '{:?}' does not exist or is not a SystemStage",
stage_label
Expand Down

0 comments on commit 45fc8c7

Please sign in to comment.