diff options
| author | mat <git@matdoes.dev> | 2026-05-06 03:36:16 -0100 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2026-05-07 08:05:58 -1200 |
| commit | 9ffd0e80bbb3feace231553d6539124585b03e3c (patch) | |
| tree | ad8df7d07df9f8f542e288c263d76b8ffd637416 /azalea/src/client_impl/error.rs | |
| parent | 4d1f430408dc6854c1af5fb14b2641e293a9cf43 (diff) | |
| download | azalea-drasl-9ffd0e80bbb3feace231553d6539124585b03e3c.tar.xz | |
change panicking functions in Client and EntityRef to return an AzaleaResult instead
Diffstat (limited to 'azalea/src/client_impl/error.rs')
| -rw-r--r-- | azalea/src/client_impl/error.rs | 29 |
1 files changed, 29 insertions, 0 deletions
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<T, MissingComponentError>`, 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<T> = Result<T, MissingComponentError>; |
