bevy_ecs/query/
error.rs

1use thiserror::Error;
2
3use crate::entity::Entity;
4
5/// An error that occurs when retrieving a specific [`Entity`]'s query result from [`Query`](crate::system::Query) or [`QueryState`](crate::query::QueryState).
6// TODO: return the type_name as part of this error
7#[derive(Debug, PartialEq, Eq, Clone, Copy, Error)]
8pub enum QueryEntityError {
9    /// The given [`Entity`]'s components do not match the query.
10    ///
11    /// Either it does not have a requested component, or it has a component which the query filters out.
12    #[error("The components of entity {0:?} do not match the query")]
13    QueryDoesNotMatch(Entity),
14    /// The given [`Entity`] does not exist.
15    #[error("The entity {0:?} does not exist")]
16    NoSuchEntity(Entity),
17    /// The [`Entity`] was requested mutably more than once.
18    ///
19    /// See [`QueryState::get_many_mut`](crate::query::QueryState::get_many_mut) for an example.
20    #[error("The entity {0:?} was requested mutably more than once")]
21    AliasedMutability(Entity),
22}
23
24/// An error that occurs when evaluating a [`Query`](crate::system::Query) or [`QueryState`](crate::query::QueryState) as a single expected result via
25/// [`get_single`](crate::system::Query::get_single) or [`get_single_mut`](crate::system::Query::get_single_mut).
26#[derive(Debug, Error)]
27pub enum QuerySingleError {
28    /// No entity fits the query.
29    #[error("No entities fit the query {0}")]
30    NoEntities(&'static str),
31    /// Multiple entities fit the query.
32    #[error("Multiple entities fit the query {0}")]
33    MultipleEntities(&'static str),
34}