Skip to content

Add Result handling to Commands and EntityCommands #17043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 34 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9c4884b
initial error handling
JaySpruce Dec 30, 2024
fdc4105
Squashed commit of the following:
JaySpruce Dec 30, 2024
1d63497
incorporate command struct refactors
JaySpruce Dec 30, 2024
b8d4938
remove `String` from `EntityFetchError`, fix benches
JaySpruce Dec 30, 2024
0d75dac
rename `queue_with_error_handling` to `queue_fallible`
JaySpruce Dec 30, 2024
62abe41
let `Commands::entity` return invalid `EntityCommands`
JaySpruce Dec 30, 2024
1ea5b50
forgot about `EntityEntryCommands`
JaySpruce Dec 30, 2024
5028d02
add `Error` and `Override` error modes
JaySpruce Dec 30, 2024
60ddd45
Merge branch 'bevyengine:main' into command_error_handling
JaySpruce Dec 30, 2024
819897c
give world and error to custom error mode, small renames
JaySpruce Dec 31, 2024
0e0eb15
add docs
JaySpruce Dec 31, 2024
e814dbd
maintain `error_mode` on reborrow
JaySpruce Dec 31, 2024
ae978e6
implement suggestions, try out the above idea
JaySpruce Jan 2, 2025
51f0634
Merge branch 'main' into command_error_handling
JaySpruce Jan 2, 2025
eb3503d
fix `track_location`
JaySpruce Jan 2, 2025
1708b44
fix `EntityFetchError::NoSuchEntity`
JaySpruce Jan 2, 2025
97bffd9
revert all `EntityFetchError` changes (we have our own now)
JaySpruce Jan 2, 2025
2bc92c6
cargo fmt
JaySpruce Jan 2, 2025
9e48772
nevermind we do need it lmao
JaySpruce Jan 2, 2025
ec6cc96
bring some docs over from 15929
JaySpruce Jan 2, 2025
92213dc
Merge branch 'main' into command_error_handling
JaySpruce Jan 3, 2025
edbd160
use `CommandError` instead of `Box<dyn Error>`
JaySpruce Jan 3, 2025
6722002
imports in doctests
JaySpruce Jan 3, 2025
1cf8b58
nits
JaySpruce Jan 4, 2025
f989c7e
move entity existence check to `with_entity`
JaySpruce Jan 4, 2025
c15bd43
small docs
JaySpruce Jan 4, 2025
74089d1
Merge branch 'main' into command_error_handling
JaySpruce Jan 4, 2025
a66d67f
Merge branch 'main' into command_error_handling
JaySpruce Jan 5, 2025
4a897c7
split command stuff into new files
JaySpruce Jan 6, 2025
e23540f
Merge branch 'main' into command_error_handling
JaySpruce Jan 6, 2025
e5e8a88
some docs, add `Command::apply_internal`
JaySpruce Jan 6, 2025
07f75e6
tiny doctest fix
JaySpruce Jan 6, 2025
d2dba34
change `with_error_handling` to return `impl Command`
JaySpruce Jan 6, 2025
4259e4d
tiny docs
JaySpruce Jan 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions benches/benches/bevy_ecs/world/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ use core::hint::black_box;

use bevy_ecs::{
component::Component,
system::Commands,
world::{Command, CommandQueue, World},
result::Result,
system::{Command, Commands},
world::{CommandQueue, World},
};
use criterion::Criterion;

Expand Down Expand Up @@ -136,16 +137,18 @@ struct FakeCommandA;
struct FakeCommandB(u64);

impl Command for FakeCommandA {
fn apply(self, world: &mut World) {
fn apply(self, world: &mut World) -> Result {
black_box(self);
black_box(world);
Ok(())
}
}

impl Command for FakeCommandB {
fn apply(self, world: &mut World) {
fn apply(self, world: &mut World) -> Result {
black_box(self);
black_box(world);
Ok(())
}
}

Expand Down Expand Up @@ -180,9 +183,10 @@ pub fn fake_commands(criterion: &mut Criterion) {
struct SizedCommand<T: Default + Send + Sync + 'static>(T);

impl<T: Default + Send + Sync + 'static> Command for SizedCommand<T> {
fn apply(self, world: &mut World) {
fn apply(self, world: &mut World) -> Result {
black_box(self);
black_box(world);
Ok(())
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_ecs/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,12 @@ impl SparseSetIndex for BundleId {
}
}

// What to do on insertion if component already exists
/// What to do on insertion if a component already exists.
#[derive(Clone, Copy, Eq, PartialEq)]
pub(crate) enum InsertMode {
pub enum InsertMode {
/// Any existing components of a matching type will be overwritten.
Replace,
/// Any existing components of a matching type will kept unchanged.
/// Any existing components of a matching type will be left unchanged.
Keep,
}

Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_ecs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ pub mod prelude {
IntoSystemSet, IntoSystemSetConfigs, Schedule, Schedules, SystemSet,
},
system::{
Commands, Deferred, EntityCommand, EntityCommands, In, InMut, InRef, IntoSystem, Local,
NonSend, NonSendMut, ParamSet, Populated, Query, ReadOnlySystem, Res, ResMut, Resource,
Single, System, SystemIn, SystemInput, SystemParamBuilder, SystemParamFunction,
WithParamWarnPolicy,
Command, Commands, Deferred, EntityCommand, EntityCommands, In, InMut, InRef,
IntoSystem, Local, NonSend, NonSendMut, ParamSet, Populated, Query, ReadOnlySystem,
Res, ResMut, Resource, Single, System, SystemIn, SystemInput, SystemParamBuilder,
SystemParamFunction, WithParamWarnPolicy,
},
world::{
Command, EntityMut, EntityRef, EntityWorldMut, FilteredResources, FilteredResourcesMut,
EntityMut, EntityRef, EntityWorldMut, FilteredResources, FilteredResourcesMut,
FromWorld, OnAdd, OnInsert, OnRemove, OnReplace, World,
},
};
Expand Down
Loading
Loading