bevy/crates
Chris Russell 9e240ee99a
Improve error message for missing events (#18683)
# Objective

Improve the parameter validation error message for
`Event(Reader|Writer|Mutator)`.

System parameters defined using `#[derive(SystemParam)]`, including the
parameters for events, currently propagate the validation errors from
their subparameters. The error includes the type of the failing
parameter, so the resulting error includes the type of the failing
subparameter instead of the derived parameter.

In particular, `EventReader<T>` will report an error from a
`Res<Events<T>>`, even though the user has no parameter of that type!

This is a follow-up to #18593.

## Solution

Have `#[derive]`d system parameters map errors during propagation so
that they report the outer parameter type.

To continue to provide context, add a field to
`SystemParamValidationError` that identifies the subparameter by name,
and is empty for non-`#[derive]`d parameters.

Allow them to override the failure message for individual parameters.
Use this to convert "Resource does not exist" to "Event not initialized"
for `Event(Reader|Writer|Mutator)`.

## Showcase

The validation error for a `EventReader<SomeEvent>` parameter when
`add_event` has not been called changes from:

Before: 
```
Parameter `Res<Events<SomeEvent>>` failed validation: Resource does not exist
```

After
```
Parameter `EventReader<SomeEvent>::events` failed validation: Event not initialized
```
2025-04-02 19:25:48 +00:00
..
bevy_a11y Update accesskit and accesskit_winit requirements (#18285) 2025-03-25 04:04:28 +00:00
bevy_animation Fix animation transitions affecting other entities (#18572) 2025-03-27 21:33:25 +00:00
bevy_anti_aliasing Remove Image::from_buffer name argument (only present in debug "dds" builds) (#18538) 2025-03-25 19:25:01 +00:00
bevy_app Add sleep based on spin to bevy_platform_support (#18633) 2025-03-31 23:21:49 +00:00
bevy_asset Only send unused event when final handle is dropped. (#18641) 2025-03-31 18:05:59 +00:00
bevy_audio
bevy_color
bevy_core_pipeline reexport entity set collections in entity module (#18413) 2025-03-30 03:51:14 +00:00
bevy_derive Link iOS example with rustc, and avoid C trampoline (#14780) 2025-03-17 21:14:07 +00:00
bevy_dev_tools
bevy_diagnostic Fix LogDiagnosticsPlugin log target typo (#18534) 2025-03-29 17:07:21 +00:00
bevy_dylib Switch from OnceCell to LazyLock in bevy_tasks (#18506) 2025-03-24 07:43:22 +00:00
bevy_ecs Improve error message for missing events (#18683) 2025-04-02 19:25:48 +00:00
bevy_encase_derive
bevy_gilrs reexport entity set collections in entity module (#18413) 2025-03-30 03:51:14 +00:00
bevy_gizmos Rename EntityBorrow/TrustedEntityBorrow to ContainsEntity/EntityEquivalent (#18470) 2025-03-30 06:04:26 +00:00
bevy_gltf reexport entity set collections in entity module (#18413) 2025-03-30 03:51:14 +00:00
bevy_image bevy_image: derive TypePath when Reflect is not available (#18501) 2025-03-30 02:50:24 +00:00
bevy_input
bevy_input_focus Switch ChildOf back to tuple struct (#18672) 2025-04-02 00:10:10 +00:00
bevy_internal Upgrade to Glam 0.29.3 and Simplify Feature Gating (#18638) 2025-03-31 18:54:46 +00:00
bevy_log
bevy_macro_utils
bevy_math Upgrade to Glam 0.29.3 and Simplify Feature Gating (#18638) 2025-03-31 18:54:46 +00:00
bevy_mesh Reduce dependencies on bevy_render by preferring bevy_mesh imports (#18437) 2025-03-25 04:14:42 +00:00
bevy_mikktspace Upgrade to Glam 0.29.3 and Simplify Feature Gating (#18638) 2025-03-31 18:54:46 +00:00
bevy_pbr Bump crate-ci/typos from 1.30.2 to 1.31.0 (#18656) 2025-04-02 10:59:15 +00:00
bevy_picking Switch ChildOf back to tuple struct (#18672) 2025-04-02 00:10:10 +00:00
bevy_platform_support Add sleep based on spin to bevy_platform_support (#18633) 2025-03-31 23:21:49 +00:00
bevy_ptr
bevy_reflect Upgrade to Glam 0.29.3 and Simplify Feature Gating (#18638) 2025-03-31 18:54:46 +00:00
bevy_remote Fix indentation of bevy/query strict parameter in docs (#18681) 2025-04-02 17:33:02 +00:00
bevy_render Switch ChildOf back to tuple struct (#18672) 2025-04-02 00:10:10 +00:00
bevy_scene Switch ChildOf back to tuple struct (#18672) 2025-04-02 00:10:10 +00:00
bevy_sprite Parallelize bevy 0.16-rc bottlenecks (#18632) 2025-03-31 18:32:45 +00:00
bevy_state Fix misleading documentation of Main schedule (#18579) 2025-03-28 01:12:19 +00:00
bevy_tasks Switch from OnceCell to LazyLock in bevy_tasks (#18506) 2025-03-24 07:43:22 +00:00
bevy_text Switch ChildOf back to tuple struct (#18672) 2025-04-02 00:10:10 +00:00
bevy_time Fix clippy::unnecessary-literal-unwrap in bevy_time (#18485) 2025-03-22 13:27:37 +00:00
bevy_transform Switch ChildOf back to tuple struct (#18672) 2025-04-02 00:10:10 +00:00
bevy_ui Switch ChildOf back to tuple struct (#18672) 2025-04-02 00:10:10 +00:00
bevy_utils Address clippy::let_and_return in bevy_utils (#18480) 2025-03-22 11:44:49 +00:00
bevy_window Rename EntityBorrow/TrustedEntityBorrow to ContainsEntity/EntityEquivalent (#18470) 2025-03-30 06:04:26 +00:00
bevy_winit Switch ChildOf back to tuple struct (#18672) 2025-04-02 00:10:10 +00:00