-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Document query errors #8692
Document query errors #8692
Conversation
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
(Just in case, here is the file I used to test the example:) use bevy::app::App;
use bevy::ecs::{prelude::*, system::QueryComponentError};
#[derive(Component)]
struct OtherComponent;
#[derive(Component)]
struct RequestedComponent;
#[derive(Resource)]
struct SpecificEntity {
entity: Entity,
}
fn get_missing_read_access_error(query: Query<&RequestedComponent>, res: Res<SpecificEntity>) {
if let Err(QueryComponentError::MissingReadAccess) = query.get_component::<OtherComponent>(res.entity) {
println!("query doesn't have read access to OtherComponent");
}
}
fn get_missing_write_access_error(mut query: Query<&RequestedComponent>, res: Res<SpecificEntity>) {
if let Err(QueryComponentError::MissingWriteAccess) = query.get_component_mut::<RequestedComponent>(res.entity) {
println!("query doesn't have write access to RequestedComponent");
}
}
fn main() {
App::new()
.add_startup_system(setup)
.add_system(get_missing_read_access_error)
.add_system(get_missing_write_access_error.after(get_missing_read_access_error))
.run();
}
fn setup(
mut commands: Commands,
) {
let entity = commands.spawn((RequestedComponent, OtherComponent)).id();
commands.insert_resource(SpecificEntity{entity})
}``` |
Co-authored-by: harudagondi <giogdeasis@gmail.com>
Co-authored-by: harudagondi <giogdeasis@gmail.com>
Co-authored-by: harudagondi <giogdeasis@gmail.com>
Applied rustfmt (sorry I thought it was applied automatically somehow) |
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.
looks good to me
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.
Great work, these are much better. Thanks for improving these :)
@Selene-Amanita it looks like your doc tests are failing: can you fix those up? |
Head branch was pushed to by a user without write access
@alice-i-cecile I fixed the check-docs check, I think. I couldn't run cargo miri ("the 'miri' component which provides the command 'cargo-miri' is not available for the 'stable-x86_64-unknown-linux-gnu' toolchain") so hopefully this will work out too. Btw should I use an assert inside the system in the doc test, to check that this scenario does yield the expected error? |
Yeah, I would put an assert inside the doc test: it'll act as both clarification and as an extra layer of safety for our ECS code. Miri won't be doing anything special here: just making sure the tests all pass, so you don't need to worry about it. |
Okay! The checks did pass this time but I added
|
Mostly we just suffer here :( The tooling for doc tests is really subpar in general, which is a shame because they're very useful. Manually matching it is way more work than it's worth though.
That's fine.
Great!
Good choice. Merging! |
Objective
Add documentation to
Query
andQueryState
errors in bevy_ecs (QuerySingleError
,QueryEntityError
,QueryComponentError
)Solution
QueryEntityError::QueryDoesNotMatch
: this error can also happen when the entity has a component which is filtered out (withWithout<C>
)Query::get_component
andQuery::get_component_mut
fromQueryEntityError
toQueryComponentError
QueryComponentError::MissingReadAccess
andQueryComponentError::MissingWriteAccess
QueryState
inQueryEntityError
's documentation.Migration Guide
Expect
QueryEntityError::QueryDoesNotMatch
's display message to change? Not sure that counts.