Skip to content

Commit

Permalink
Renamed members of ParamWarnPolicy to reflect new behaviour. (#17311)
Browse files Browse the repository at this point in the history
- `Once` renamed to `Warn`.
- `param_warn_once()` renamed to `warn_param_missing()`.
- `never_param_warn()` renamed to `ignore_param_missing()`.

Also includes changes to the documentation of the above methods.

Fixes #17262.

## Migration Guide
- `ParamWarnPolicy::Once` has been renamed to `ParamWarnPolicy::Warn`.
- `ParamWarnPolicy::param_warn_once` has been renamed to
`ParamWarnPolicy::warn_param_missing`.
- `ParamWarnPolicy::never_param_warn` has been renamed to
`ParamWarnPolicy::ignore_param_missing`.
  • Loading branch information
AlephCubed authored Jan 12, 2025
1 parent f5d38f3 commit e808fbe
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
10 changes: 5 additions & 5 deletions crates/bevy_ecs/src/schedule/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ mod tests {
(|mut commands: Commands| {
commands.insert_resource(R2);
})
.param_warn_once(),
.warn_param_missing(),
)
.chain(),
);
Expand All @@ -367,20 +367,20 @@ mod tests {
let mut world = World::new();
let mut schedule = Schedule::default();
schedule.set_executor_kind(executor);
schedule.configure_sets(S1.run_if((|_: Res<R1>| true).param_warn_once()));
schedule.configure_sets(S1.run_if((|_: Res<R1>| true).warn_param_missing()));
schedule.add_systems((
// System gets skipped if system set run conditions fail validation.
(|mut commands: Commands| {
commands.insert_resource(R1);
})
.param_warn_once()
.warn_param_missing()
.in_set(S1),
// System gets skipped if run conditions fail validation.
(|mut commands: Commands| {
commands.insert_resource(R2);
})
.param_warn_once()
.run_if((|_: Res<R2>| true).param_warn_once()),
.warn_param_missing()
.run_if((|_: Res<R2>| true).warn_param_missing()),
));
schedule.run(&mut world);
assert!(world.get_resource::<R1>().is_none());
Expand Down
14 changes: 7 additions & 7 deletions crates/bevy_ecs/src/system/function_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub enum ParamWarnPolicy {
/// No warning should ever be emitted.
Never,
/// The warning will be emitted once and status will update to [`Self::Never`].
Once,
Warn,
}

impl ParamWarnPolicy {
Expand All @@ -218,7 +218,7 @@ impl ParamWarnPolicy {
name,
disqualified::ShortName::of::<P>()
),
Self::Once => {
Self::Warn => {
log::warn!(
"{0} did not run because it requested inaccessible system parameter {1}",
name,
Expand All @@ -241,13 +241,13 @@ where
/// Set warn policy.
fn with_param_warn_policy(self, warn_policy: ParamWarnPolicy) -> FunctionSystem<M, F>;

/// Warn only once about invalid system parameters.
fn param_warn_once(self) -> FunctionSystem<M, F> {
self.with_param_warn_policy(ParamWarnPolicy::Once)
/// Warn and ignore systems with invalid parameters.
fn warn_param_missing(self) -> FunctionSystem<M, F> {
self.with_param_warn_policy(ParamWarnPolicy::Warn)
}

/// Disable all param warnings.
fn never_param_warn(self) -> FunctionSystem<M, F> {
/// Silently ignore systems with invalid parameters.
fn ignore_param_missing(self) -> FunctionSystem<M, F> {
self.with_param_warn_policy(ParamWarnPolicy::Never)
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/system/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ mod tests {

let mut world = World::default();
// This fails because `T` has not been added to the world yet.
let result = world.run_system_once(system.param_warn_once());
let result = world.run_system_once(system.warn_param_missing());

assert!(matches!(result, Err(RunSystemError::InvalidParams(_))));
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/system/system_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ mod tests {
fn system(_: Res<T>) {}

let mut world = World::new();
let id = world.register_system(system.param_warn_once());
let id = world.register_system(system.warn_param_missing());
// This fails because `T` has not been added to the world yet.
let result = world.run_system(id);

Expand Down
8 changes: 4 additions & 4 deletions examples/ecs/fallible_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ fn main() {
.add_systems(
Update,
(
user_input.param_warn_once(),
move_targets.never_param_warn(),
move_pointer.never_param_warn(),
user_input.warn_param_missing(),
move_targets.ignore_param_missing(),
move_pointer.ignore_param_missing(),
)
.chain(),
)
.add_systems(Update, do_nothing_fail_validation.param_warn_once())
.add_systems(Update, do_nothing_fail_validation.warn_param_missing())
.run();
}

Expand Down

0 comments on commit e808fbe

Please sign in to comment.