Skip to content

Commit 4ad5f46

Browse files
JaySprucemockersf
authored andcommitted
Add notes to fallible commands (#18649)
Follow-up to #18639. Fallible commands should have notes explaining how they can fail, what error they return, and how it's handled.
1 parent 11ad3b6 commit 4ad5f46

File tree

1 file changed

+61
-12
lines changed
  • crates/bevy_ecs/src/system/commands

1 file changed

+61
-12
lines changed

crates/bevy_ecs/src/system/commands/mod.rs

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,13 @@ impl<'w, 's> Commands<'w, 's> {
689689
/// This method is equivalent to iterating the batch
690690
/// and calling [`insert`](EntityCommands::insert) for each pair,
691691
/// but is faster by caching data that is shared between entities.
692+
///
693+
/// # Fallible
694+
///
695+
/// This command will fail if any of the given entities do not exist.
696+
///
697+
/// It will internally return a [`TryInsertBatchError`](crate::world::error::TryInsertBatchError),
698+
/// which will be handled by the [default error handler](crate::error::default_error_handler).
692699
#[track_caller]
693700
pub fn insert_batch<I, B>(&mut self, batch: I)
694701
where
@@ -713,6 +720,13 @@ impl<'w, 's> Commands<'w, 's> {
713720
/// This method is equivalent to iterating the batch
714721
/// and calling [`insert_if_new`](EntityCommands::insert_if_new) for each pair,
715722
/// but is faster by caching data that is shared between entities.
723+
///
724+
/// # Fallible
725+
///
726+
/// This command will fail if any of the given entities do not exist.
727+
///
728+
/// It will internally return a [`TryInsertBatchError`](crate::world::error::TryInsertBatchError),
729+
/// which will be handled by the [default error handler](crate::error::default_error_handler).
716730
#[track_caller]
717731
pub fn insert_batch_if_new<I, B>(&mut self, batch: I)
718732
where
@@ -737,7 +751,12 @@ impl<'w, 's> Commands<'w, 's> {
737751
/// and calling [`insert`](EntityCommands::insert) for each pair,
738752
/// but is faster by caching data that is shared between entities.
739753
///
740-
/// This command will emit a warning if any of the given entities do not exist.
754+
/// # Fallible
755+
///
756+
/// This command will fail if any of the given entities do not exist.
757+
///
758+
/// It will internally return a [`TryInsertBatchError`](crate::world::error::TryInsertBatchError),
759+
/// which will be handled by [logging the error at the `warn` level](warn).
741760
#[track_caller]
742761
pub fn try_insert_batch<I, B>(&mut self, batch: I)
743762
where
@@ -763,7 +782,12 @@ impl<'w, 's> Commands<'w, 's> {
763782
/// and calling [`insert_if_new`](EntityCommands::insert_if_new) for each pair,
764783
/// but is faster by caching data that is shared between entities.
765784
///
766-
/// This command will emit a warning if any of the given entities do not exist.
785+
/// # Fallible
786+
///
787+
/// This command will fail if any of the given entities do not exist.
788+
///
789+
/// It will internally return a [`TryInsertBatchError`](crate::world::error::TryInsertBatchError),
790+
/// which will be handled by [logging the error at the `warn` level](warn).
767791
#[track_caller]
768792
pub fn try_insert_batch_if_new<I, B>(&mut self, batch: I)
769793
where
@@ -860,8 +884,13 @@ impl<'w, 's> Commands<'w, 's> {
860884
/// execution of the system happens later. To get the output of a system, use
861885
/// [`World::run_system`] or [`World::run_system_with`] instead of running the system as a command.
862886
///
863-
/// If no system corresponds to the given [`SystemId`],
864-
/// this command will emit a warning.
887+
/// # Fallible
888+
///
889+
/// This command will fail if the given [`SystemId`]
890+
/// does not correspond to a [`System`](crate::system::System).
891+
///
892+
/// It will internally return a [`RegisteredSystemError`](crate::system::system_registry::RegisteredSystemError),
893+
/// which will be handled by [logging the error at the `warn` level](warn).
865894
pub fn run_system(&mut self, id: SystemId) {
866895
self.queue(command::run_system(id).handle_error_with(warn));
867896
}
@@ -877,8 +906,13 @@ impl<'w, 's> Commands<'w, 's> {
877906
/// execution of the system happens later. To get the output of a system, use
878907
/// [`World::run_system`] or [`World::run_system_with`] instead of running the system as a command.
879908
///
880-
/// If no system corresponds to the given [`SystemId`],
881-
/// this command will emit a warning.
909+
/// # Fallible
910+
///
911+
/// This command will fail if the given [`SystemId`]
912+
/// does not correspond to a [`System`](crate::system::System).
913+
///
914+
/// It will internally return a [`RegisteredSystemError`](crate::system::system_registry::RegisteredSystemError),
915+
/// which will be handled by [logging the error at the `warn` level](warn).
882916
pub fn run_system_with<I>(&mut self, id: SystemId<I>, input: I::Inner<'static>)
883917
where
884918
I: SystemInput<Inner<'static>: Send> + 'static,
@@ -965,8 +999,13 @@ impl<'w, 's> Commands<'w, 's> {
965999
/// and attempting to use it afterwards will result in an error.
9661000
/// Re-adding the removed system will register it with a new `SystemId`.
9671001
///
968-
/// If no system corresponds to the given [`SystemId`],
969-
/// this command will emit a warning.
1002+
/// # Fallible
1003+
///
1004+
/// This command will fail if the given [`SystemId`]
1005+
/// does not correspond to a [`System`](crate::system::System).
1006+
///
1007+
/// It will internally return a [`RegisteredSystemError`](crate::system::system_registry::RegisteredSystemError),
1008+
/// which will be handled by [logging the error at the `warn` level](warn).
9701009
pub fn unregister_system<I, O>(&mut self, system_id: SystemId<I, O>)
9711010
where
9721011
I: SystemInput + Send + 'static,
@@ -980,8 +1019,13 @@ impl<'w, 's> Commands<'w, 's> {
9801019
/// - [`World::run_system_cached`]
9811020
/// - [`World::register_system_cached`]
9821021
///
983-
/// If the given system is not currently cached,
984-
/// this command will emit a warning.
1022+
/// # Fallible
1023+
///
1024+
/// This command will fail if the given system
1025+
/// is not currently cached in a [`CachedSystemId`](crate::system::CachedSystemId) resource.
1026+
///
1027+
/// It will internally return a [`RegisteredSystemError`](crate::system::system_registry::RegisteredSystemError),
1028+
/// which will be handled by [logging the error at the `warn` level](warn).
9851029
pub fn unregister_system_cached<I, O, M, S>(&mut self, system: S)
9861030
where
9871031
I: SystemInput + Send + 'static,
@@ -1108,8 +1152,13 @@ impl<'w, 's> Commands<'w, 's> {
11081152
///
11091153
/// Calls [`World::try_run_schedule`](World::try_run_schedule).
11101154
///
1111-
/// If the schedule is not available to be run,
1112-
/// this command will emit a warning.
1155+
/// # Fallible
1156+
///
1157+
/// This command will fail if the given [`ScheduleLabel`]
1158+
/// does not correspond to a [`Schedule`](crate::schedule::Schedule).
1159+
///
1160+
/// It will internally return a [`TryRunScheduleError`](crate::world::error::TryRunScheduleError),
1161+
/// which will be handled by [logging the error at the `warn` level](warn).
11131162
///
11141163
/// # Example
11151164
///

0 commit comments

Comments
 (0)