bevy/crates
Chris Russell ac04ec0075 Improve error message for missing resources (#18593)
# Objective

Fixes #18515 

After the recent changes to system param validation, the panic message
for a missing resource is currently:

```
Encountered an error in system `missing_resource_error::res_system`: SystemParamValidationError { skipped: false }
```

Add the parameter type name and a descriptive message, improving the
panic message to:

```
Encountered an error in system `missing_resource_error::res_system`: SystemParamValidationError { skipped: false, message: "Resource does not exist", param: "bevy_ecs::change_detection::Res<missing_resource_error::MissingResource>" }
```

## Solution

Add fields to `SystemParamValidationError` for error context. Include
the `type_name` of the param and a message.

Store them as `Cow<'static, str>` and only format them into a friendly
string in the `Display` impl. This lets us create errors using a
`&'static str` with no allocation or formatting, while still supporting
runtime `String` values if necessary.

Add a unit test that verifies the panic message.

## Future Work

If we change the default error handling to use `Display` instead of
`Debug`, and to use `ShortName` for the system name, the panic message
could be further improved to:

```
Encountered an error in system `res_system`: Parameter `Res<MissingResource>` failed validation: Resource does not exist
```

However, `BevyError` currently includes the backtrace in `Debug` but not
`Display`, and I didn't want to try to change that in this PR.
2025-03-30 10:21:20 +02:00
..
bevy_a11y Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_animation Fix animation transitions affecting other entities (#18572) 2025-03-27 22:58:21 +01:00
bevy_app Fix misleading documentation of Main schedule (#18579) 2025-03-28 23:33:00 +01:00
bevy_asset Revert PR #15481 to resolve a regression. (#18567) 2025-03-27 22:58:18 +01:00
bevy_audio Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_color Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_core_pipeline Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_derive Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_dev_tools Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_diagnostic Fix LogDiagnosticsPlugin log target typo (#18534) 2025-03-30 10:21:19 +02:00
bevy_dylib Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_ecs Improve error message for missing resources (#18593) 2025-03-30 10:21:20 +02:00
bevy_encase_derive Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_gilrs Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_gizmos Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_gltf Revert PR #15481 to resolve a regression. (#18567) 2025-03-27 22:58:18 +01:00
bevy_image Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_input Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_input_focus Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_internal Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_log Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_macro_utils Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_math Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_mesh Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_mikktspace Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_pbr Expose skins_use_uniform_buffers() necessary to use pre-existing setup_morph_and_skinning_defs() API. (#18612) 2025-03-30 10:21:20 +02:00
bevy_picking Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_platform_support Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_ptr Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_reflect bevy_reflect: Fix TypePath string concatenation (#18609) 2025-03-30 10:21:19 +02:00
bevy_remote Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_render Improve error message for missing resources (#18593) 2025-03-30 10:21:20 +02:00
bevy_scene Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_sprite Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_state Fix misleading documentation of Main schedule (#18579) 2025-03-28 23:33:00 +01:00
bevy_tasks Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_text Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_time Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_transform Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_ui Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_utils Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_window Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00
bevy_winit Release 0.16.0-rc.2 2025-03-26 19:18:20 +01:00