use crate::InspectEntity;
use bevy::ecs::entity::Entity;
use std::any::type_name;
#[cfg(feature = "full_types")]
fn fmt(s: &str) -> &str {
s
}
#[cfg(not(feature = "full_types"))]
fn fmt(s: &str) -> String {
pretty_type_name::pretty_type_name_str(s)
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
#[non_exhaustive]
pub enum AccessError {
#[error("async channel closed")]
ChannelClosed,
#[error("entity {} not found", InspectEntity(*.0))]
EntityNotFound(Entity),
#[error("query condition {} not met for entity {}", fmt(query), InspectEntity(*entity))]
QueryConditionNotMet { entity: Entity, query: &'static str },
#[error("single entity not found in query {}", fmt(query))]
NoEntityFound { query: &'static str },
#[error("too many entities found in query {}", fmt(query))]
TooManyEntities { query: &'static str },
#[error("child index {index} missing")]
ChildNotFound { index: usize },
#[error("component <{}> not found", fmt(name))]
ComponentNotFound { name: &'static str },
#[error("resource <{}> not found", fmt(name))]
ResourceNotFound { name: &'static str },
#[error("asset <{}> not found", fmt(name))]
AssetNotFound { name: &'static str },
#[error("event <{}> not registered", fmt(name))]
EventNotRegistered { name: &'static str },
#[error("downcast ({}) failed", fmt(name))]
DowncastFailed { name: &'static str },
#[error("schedule not found")]
ScheduleNotFound,
#[error("SystemId not found")]
SystemIdNotFound,
#[error("Task spawned has panicked")]
TaskPanicked,
#[error("not in a state of type {}", fmt(ty))]
NotInState { ty: &'static str },
#[error("custom error: {0}")]
Custom(&'static str),
#[error("typed error: {message} of type {}", fmt(ty))]
TypedError {
message: &'static &'static str,
ty: &'static str,
},
#[error("this error should not happen")]
ShouldNotHappen,
#[deprecated = "Signal related methods now automatically adds them."]
#[error("signal <{}> not found", fmt(name))]
SignalNotFound { name: &'static str },
#[deprecated]
#[error("system param error")]
SystemParamError,
#[deprecated]
#[error("AsyncWorldParam not found")]
WorldParamNotFound,
#[deprecated]
#[error("name not found")]
NameNotFound,
#[deprecated]
#[error("io error")]
IO,
}
impl AccessError {
pub fn component<T>() -> Self {
AccessError::ComponentNotFound {
name: type_name::<T>(),
}
}
pub fn resource<T>() -> Self {
AccessError::ResourceNotFound {
name: type_name::<T>(),
}
}
pub fn asset<T>() -> Self {
AccessError::AssetNotFound {
name: type_name::<T>(),
}
}
}