From 9ffd0e80bbb3feace231553d6539124585b03e3c Mon Sep 17 00:00:00 2001 From: mat Date: Wed, 6 May 2026 03:36:16 -0100 Subject: change panicking functions in Client and EntityRef to return an AzaleaResult instead --- azalea/src/client_impl/error.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 azalea/src/client_impl/error.rs (limited to 'azalea/src/client_impl/error.rs') diff --git a/azalea/src/client_impl/error.rs b/azalea/src/client_impl/error.rs new file mode 100644 index 00000000..ce3ecab4 --- /dev/null +++ b/azalea/src/client_impl/error.rs @@ -0,0 +1,29 @@ +use bevy_ecs::entity::Entity; +use thiserror::Error; + +/// An error that occurs when we tried to access data from an entity that it +/// doesn't have. +/// +/// This could happen because the data does not occur for this type of entity, +/// or because the entity is not currently loaded. +/// +/// If this error happened when trying to access data on a client, then it may +/// be because the client isn't currently in a world. +/// +/// As an alias for `Result`, you may use +/// [`AzaleaResult`]. Using the `eyre` or `anyhow` crates may also simplify +/// error handling in your bots. +#[derive(Error, Debug)] +#[error("{entity_description} {entity} is missing a required component: '{component}'")] +pub struct MissingComponentError { + /// Should be "Entity" or "Client" + pub entity_description: &'static str, + pub entity: Entity, + pub component: &'static str, +} + +/// An error that occurs when we tried to access data from an entity that it +/// doesn't have. +/// +/// See [`MissingComponentError`] for more details. +pub type AzaleaResult = Result; -- cgit v1.2.3