Skip to content

Commit

Permalink
improve a panic message
Browse files Browse the repository at this point in the history
  • Loading branch information
JoJoJet committed Jul 29, 2022
1 parent cb54639 commit b611dfd
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions crates/bevy_app/src/sub_schedule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,15 @@ pub(crate) fn add_to_app<S: Stage>(app: &mut App, schedule: impl IntoSubSchedule
s
} else {
#[cfg(debug_assertions)]
unreachable!("the sub-schedule '{label:?}' somehow changed type after being inserted!");
unreachable!(
r#"
The sub-schedule '{label:?}' changed types after being inserted:
it should be of type `{expect}`, but it's really of type `{actual}`.
This should be impossible.
If run into this error, please file an issue at https://github.com/bevyengine/bevy/issues/new/choose"#,
expect = std::any::type_name::<S>(),
actual = AnyTypeName::name(sched),
);
// SAFETY: Due to the invariant on `SubSchedules`, we can be sure that
// `sched` is the same instance that we inserted.
// Thus, we can rely on its type matching `S`.
Expand All @@ -238,7 +246,8 @@ pub(crate) fn add_to_app<S: Stage>(app: &mut App, schedule: impl IntoSubSchedule
}
};
runner(sched, w);
}).unwrap();
})
.unwrap();
};
app.add_system_to_stage(stage, driver.exclusive_system());
}
Expand All @@ -253,3 +262,13 @@ pub(crate) fn add_to_app<S: Stage>(app: &mut App, schedule: impl IntoSubSchedule
panic!("inserted sub-schedule can never be accessed, as it has neither a label nor a runner function")
}
}

/// Trait that lets us get the type name of a trait object for debugging purposes.
trait AnyTypeName: 'static {
fn name(&self) -> &'static str;
}
impl<T: ?Sized + 'static> AnyTypeName for T {
fn name(&self) -> &'static str {
std::any::type_name::<Self>()
}
}

0 comments on commit b611dfd

Please sign in to comment.