From fbb9b3644189aa2164cbdade33aebdf8ea0fc428 Mon Sep 17 00:00:00 2001 From: Isaac Corbrey Date: Wed, 18 Sep 2024 09:43:06 -0400 Subject: [PATCH] Throw real error messages on all failed attempts to get `StateTransition` schedule (#15284) # Objective Make it clear to the user why their program is failing rather than having an unhelpful `called Option::unwrap() on a None value` message. ## Solution Change the `unwrap()` calls to `expect()` calls, mirroring previously implemented error messages. ## Testing I have not tested these changes, but they are fairly trivial so I do not necessarily feel they need it. --- crates/bevy_state/src/app.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/bevy_state/src/app.rs b/crates/bevy_state/src/app.rs index f550e8daa0..4541a1cd5d 100644 --- a/crates/bevy_state/src/app.rs +++ b/crates/bevy_state/src/app.rs @@ -117,7 +117,7 @@ impl AppExtStates for SubApp { .init_resource::>() .add_event::>(); let schedule = self.get_schedule_mut(StateTransition).expect( - "The `StateTransition` schedule is missing. Did you forget to add StatesPlugin or DefaultPlugins before calling init_state?" + "The `StateTransition` schedule is missing. Did you forget to add StatesPlugin or DefaultPlugins before calling insert_state?" ); S::register_state(schedule); self.world_mut().send_event(StateTransitionEvent { @@ -146,7 +146,9 @@ impl AppExtStates for SubApp { .contains_resource::>>() { self.add_event::>(); - let schedule = self.get_schedule_mut(StateTransition).unwrap(); + let schedule = self.get_schedule_mut(StateTransition).expect( + "The `StateTransition` schedule is missing. Did you forget to add StatesPlugin or DefaultPlugins before calling add_computed_state?" + ); S::register_computed_state_systems(schedule); let state = self .world() @@ -172,7 +174,9 @@ impl AppExtStates for SubApp { { self.init_resource::>(); self.add_event::>(); - let schedule = self.get_schedule_mut(StateTransition).unwrap(); + let schedule = self.get_schedule_mut(StateTransition).expect( + "The `StateTransition` schedule is missing. Did you forget to add StatesPlugin or DefaultPlugins before calling add_sub_state?" + ); S::register_sub_state_systems(schedule); let state = self .world()