mod attribute;
mod execution;
mod internal;
mod move_error;
mod primitives;
mod registry;
mod spawn;
pub use primitives::{
CapacityError, PositionOutOfBoundsError, ShardBoundsError, StaleEntityError, TypeMismatchError,
};
pub use attribute::{AttributeError, AttributeInvariantViolation};
pub use registry::{RegistryError, RegistryResult};
pub use spawn::SpawnError;
pub use move_error::MoveError;
pub use execution::{AccessKind, BoundaryAccessFailure, ExecutionError, InvalidAccessReason};
pub use internal::InternalViolation;
#[non_exhaustive]
#[derive(Debug, Clone)]
pub enum ECSError {
Spawn(SpawnError),
Execute(ExecutionError),
Move(MoveError),
Registry(RegistryError),
Attribute(AttributeError),
Internal(InternalViolation),
#[cfg(feature = "environment")]
Environment(crate::environment::error::EnvironmentError),
#[cfg(feature = "messaging")]
Messaging(crate::messaging::error::MessagingError),
#[cfg(feature = "agents")]
Agent(crate::agents::error::AgentError),
}
impl std::fmt::Display for ECSError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ECSError::Spawn(e) => write!(f, "spawn error: {e}"),
ECSError::Execute(e) => write!(f, "execution error: {e}"),
ECSError::Move(e) => write!(f, "move error: {e}"),
ECSError::Registry(e) => write!(f, "registry error: {e}"),
ECSError::Attribute(e) => write!(f, "attribute error: {e}"),
ECSError::Internal(v) => write!(f, "internal error: {v}"),
#[cfg(feature = "environment")]
ECSError::Environment(e) => write!(f, "environment error: {e}"),
#[cfg(feature = "messaging")]
ECSError::Messaging(e) => write!(f, "messaging error: {e}"),
#[cfg(feature = "agents")]
ECSError::Agent(e) => write!(f, "agent error: {e}"),
}
}
}
impl std::error::Error for ECSError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
ECSError::Spawn(e) => Some(e),
ECSError::Execute(e) => Some(e),
ECSError::Move(e) => Some(e),
ECSError::Registry(e) => Some(e),
ECSError::Attribute(e) => Some(e),
ECSError::Internal(v) => Some(v),
#[cfg(feature = "environment")]
ECSError::Environment(e) => Some(e),
#[cfg(feature = "messaging")]
ECSError::Messaging(e) => Some(e),
#[cfg(feature = "agents")]
ECSError::Agent(e) => Some(e),
}
}
}
impl From<SpawnError> for ECSError {
fn from(e: SpawnError) -> Self {
ECSError::Spawn(e)
}
}
impl From<ExecutionError> for ECSError {
fn from(e: ExecutionError) -> Self {
ECSError::Execute(e)
}
}
impl From<MoveError> for ECSError {
fn from(e: MoveError) -> Self {
ECSError::Move(e)
}
}
impl From<RegistryError> for ECSError {
fn from(e: RegistryError) -> Self {
ECSError::Registry(e)
}
}
impl From<AttributeError> for ECSError {
fn from(e: AttributeError) -> Self {
ECSError::Attribute(e)
}
}
impl From<InternalViolation> for ECSError {
fn from(v: InternalViolation) -> Self {
ECSError::Internal(v)
}
}
#[cfg(feature = "environment")]
impl From<crate::environment::error::EnvironmentError> for ECSError {
fn from(e: crate::environment::error::EnvironmentError) -> Self {
ECSError::Environment(e)
}
}
#[cfg(feature = "messaging")]
impl From<crate::messaging::error::MessagingError> for ECSError {
fn from(e: crate::messaging::error::MessagingError) -> Self {
ECSError::Messaging(e)
}
}
pub type ECSResult<T> = Result<T, ECSError>;