bevy/crates
Carter Anderson 4bca7f1b6d
Improved Command Errors (#17215)
# Objective

Rework / build on #17043 to simplify the implementation. #17043 should
be merged first, and the diff from this PR will get much nicer after it
is merged (this PR is net negative LOC).

## Solution

1. Command and EntityCommand have been vastly simplified. No more marker
components. Just one function.
2. Command and EntityCommand are now generic on the return type. This
enables result-less commands to exist, and allows us to statically
distinguish between fallible and infallible commands, which allows us to
skip the "error handling overhead" for cases that don't need it.
3. There are now only two command queue variants: `queue` and
`queue_fallible`. `queue` accepts commands with no return type.
`queue_fallible` accepts commands that return a Result (specifically,
one that returns an error that can convert to
`bevy_ecs::result::Error`).
4. I've added the concept of the "default error handler", which is used
by `queue_fallible`. This is a simple direct call to the `panic()` error
handler by default. Users that want to override this can enable the
`configurable_error_handler` cargo feature, then initialize the
GLOBAL_ERROR_HANDLER value on startup. This is behind a flag because
there might be minor overhead with `OnceLock` and I'm guessing this will
be a niche feature. We can also do perf testing with OnceLock if someone
really wants it to be used unconditionally, but I don't personally feel
the need to do that.
5. I removed the "temporary error handler" on Commands (and all code
associated with it). It added more branching, made Commands bigger /
more expensive to initialize (note that we construct it at high
frequencies / treat it like a pointer type), made the code harder to
follow, and introduced a bunch of additional functions. We instead rely
on the new default error handler used in `queue_fallible` for most
things. In the event that a custom handler is required,
`handle_error_with` can be used.
6. EntityCommand now _only_ supports functions that take
`EntityWorldMut` (and all existing entity commands have been ported).
Removing the marker component from EntityCommand hinged on this change,
but I strongly believe this is for the best anyway, as this sets the
stage for more efficient batched entity commands.
7. I added `EntityWorldMut::resource` and the other variants for more
ergonomic resource access on `EntityWorldMut` (removes the need for
entity.world_scope, which also incurs entity-lookup overhead).

## Open Questions

1. I believe we could merge `queue` and `queue_fallible` into a single
`queue` which accepts both fallible and infallible commands (via the
introduction of a `QueueCommand` trait). Is this desirable?
2025-01-10 04:15:50 +00:00
..
bevy_a11y Update all previously-merged #![deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] attributes to include a reason field pointing to the tracking issue (#17136) 2025-01-06 05:40:08 +00:00
bevy_animation Allow tuple structs in animated_field! macro (#17234) 2025-01-08 19:04:32 +00:00
bevy_app Update downcast-rs to version 2 (#17223) 2025-01-07 21:33:40 +00:00
bevy_asset Allow clippy::too_many_arguments to lint without warnings (#17249) 2025-01-09 07:26:15 +00:00
bevy_audio bevy_audio: Apply #![deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] (#17119) 2025-01-06 19:09:08 +00:00
bevy_color Add the original source for Oklab conversions (#17199) 2025-01-07 00:41:33 +00:00
bevy_core_pipeline Allow clippy::too_many_arguments to lint without warnings (#17249) 2025-01-09 07:26:15 +00:00
bevy_derive Bump Version after Release (#17176) 2025-01-06 00:04:44 +00:00
bevy_dev_tools Upstream DebugPickingPlugin from bevy_mod_picking (#17177) 2025-01-07 05:19:50 +00:00
bevy_diagnostic bevy_diagnostic: Apply #![deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] (#17186) 2025-01-06 19:29:59 +00:00
bevy_dylib Bump Version after Release (#17176) 2025-01-06 00:04:44 +00:00
bevy_ecs Improved Command Errors (#17215) 2025-01-10 04:15:50 +00:00
bevy_encase_derive Bump Version after Release (#17176) 2025-01-06 00:04:44 +00:00
bevy_gilrs bevy_gilrs: Apply #![deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] (#17245) 2025-01-09 06:25:45 +00:00
bevy_gizmos Allow clippy::too_many_arguments to lint without warnings (#17249) 2025-01-09 07:26:15 +00:00
bevy_gltf Allow clippy::too_many_arguments to lint without warnings (#17249) 2025-01-09 07:26:15 +00:00
bevy_hierarchy Improved Command Errors (#17215) 2025-01-10 04:15:50 +00:00
bevy_image Move TextureAtlas and friends into bevy_image (#17219) 2025-01-07 18:43:11 +00:00
bevy_input bevy_input: Apply #![deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] (#17242) 2025-01-08 20:42:50 +00:00
bevy_input_focus Add a simple directional UI navigation example (#17224) 2025-01-09 21:15:28 +00:00
bevy_internal Added docs about MinimalPlugins looping as fast as possible. (#17241) 2025-01-09 06:28:06 +00:00
bevy_log bevy_log: Apply #![deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] (#17246) 2025-01-09 06:26:04 +00:00
bevy_macro_utils Bump Version after Release (#17176) 2025-01-06 00:04:44 +00:00
bevy_math Add basic directional (gamepad) navigation for UI (and non-UI) (#17102) 2025-01-06 18:51:44 +00:00
bevy_mesh bevy_mesh: Apply #![deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] (#17218) 2025-01-09 06:29:36 +00:00
bevy_mikktspace Bump Version after Release (#17176) 2025-01-06 00:04:44 +00:00
bevy_pbr Improved Command Errors (#17215) 2025-01-10 04:15:50 +00:00
bevy_picking Make sprite picking opt-in (#17225) 2025-01-09 18:11:44 +00:00
bevy_ptr bevy_ptr: Apply #![deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] (#17214) 2025-01-07 18:46:53 +00:00
bevy_reflect Update downcast-rs to version 2 (#17223) 2025-01-07 21:33:40 +00:00
bevy_remote Bump Version after Release (#17176) 2025-01-06 00:04:44 +00:00
bevy_render Allow clippy::too_many_arguments to lint without warnings (#17249) 2025-01-09 07:26:15 +00:00
bevy_scene Bump Version after Release (#17176) 2025-01-06 00:04:44 +00:00
bevy_sprite Make sprite picking opt-in (#17225) 2025-01-09 18:11:44 +00:00
bevy_state Bump Version after Release (#17176) 2025-01-06 00:04:44 +00:00
bevy_tasks Update all previously-merged #![deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] attributes to include a reason field pointing to the tracking issue (#17136) 2025-01-06 05:40:08 +00:00
bevy_text Allow clippy::too_many_arguments to lint without warnings (#17249) 2025-01-09 07:26:15 +00:00
bevy_time bevy_time: Apply #![deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] (#17210) 2025-01-09 06:29:42 +00:00
bevy_transform Improved Command Errors (#17215) 2025-01-10 04:15:50 +00:00
bevy_ui Allow clippy::too_many_arguments to lint without warnings (#17249) 2025-01-09 07:26:15 +00:00
bevy_utils Add compile-time dyn compatible checks for DynEq, DynHash (#17254) 2025-01-09 07:30:54 +00:00
bevy_window bevy_window: Apply #![deny(clippy::allow_attributes, clippy::allow_attributes_without_reason)] (#17213) 2025-01-07 18:47:10 +00:00
bevy_winit Add a simple directional UI navigation example (#17224) 2025-01-09 21:15:28 +00:00