Improve error message for missing events#18683
Merged
alice-i-cecile merged 4 commits intobevyengine:mainfrom Apr 2, 2025
Merged
Improve error message for missing events#18683alice-i-cecile merged 4 commits intobevyengine:mainfrom
alice-i-cecile merged 4 commits intobevyengine:mainfrom
Conversation
kristoff3r
approved these changes
Apr 2, 2025
alice-i-cecile
approved these changes
Apr 2, 2025
Member
alice-i-cecile
left a comment
There was a problem hiding this comment.
Lovely! @Bleachfuel, would you be able to give me a quick review here? I've really appreciated your macro expertise.
Bleachfuel
approved these changes
Apr 2, 2025
Contributor
Bleachfuel
left a comment
There was a problem hiding this comment.
LGTM! However maybe we should merge #18199 first as it makes this code more reasonable, since we now are doing all kinds of stuff inside one iter()
mockersf
pushed a commit
that referenced
this pull request
Apr 3, 2025
# 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 ```
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 aRes<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
SystemParamValidationErrorthat 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 whenadd_eventhas not been called changes from:Before:
After