-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Improve error message for missing events #18683
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
Improve error message for missing events #18683
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lovely! @Bleachfuel, would you be able to give me a quick review here? I've really appreciated your macro expertise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()
# 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 ```
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
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 whenadd_event
has not been called changes from:Before:
After