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.
This commit is contained in:
Isaac Corbrey 2024-09-18 09:43:06 -04:00 committed by GitHub
parent 69541462c5
commit fbb9b36441
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -117,7 +117,7 @@ impl AppExtStates for SubApp {
.init_resource::<NextState<S>>() .init_resource::<NextState<S>>()
.add_event::<StateTransitionEvent<S>>(); .add_event::<StateTransitionEvent<S>>();
let schedule = self.get_schedule_mut(StateTransition).expect( 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); S::register_state(schedule);
self.world_mut().send_event(StateTransitionEvent { self.world_mut().send_event(StateTransitionEvent {
@ -146,7 +146,9 @@ impl AppExtStates for SubApp {
.contains_resource::<Events<StateTransitionEvent<S>>>() .contains_resource::<Events<StateTransitionEvent<S>>>()
{ {
self.add_event::<StateTransitionEvent<S>>(); self.add_event::<StateTransitionEvent<S>>();
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); S::register_computed_state_systems(schedule);
let state = self let state = self
.world() .world()
@ -172,7 +174,9 @@ impl AppExtStates for SubApp {
{ {
self.init_resource::<NextState<S>>(); self.init_resource::<NextState<S>>();
self.add_event::<StateTransitionEvent<S>>(); self.add_event::<StateTransitionEvent<S>>();
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); S::register_sub_state_systems(schedule);
let state = self let state = self
.world() .world()