summaryrefslogtreecommitdiff
path: root/ecs/src/lib.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-05-19 00:12:11 +0200
committerHampusM <hampus@hampusmat.com>2026-05-19 00:12:11 +0200
commitd5a744b0909c4b2bec397ae4dcd43b56aba355c6 (patch)
tree1dcf8b769775ab7a0f4ff87e280aa98a0d280d21 /ecs/src/lib.rs
parentb13b3f6e13f9ac9fe7fee0b5a81b026f411f0301 (diff)
feat(ecs): add error handlingHEADmaster
Diffstat (limited to 'ecs/src/lib.rs')
-rw-r--r--ecs/src/lib.rs42
1 files changed, 38 insertions, 4 deletions
diff --git a/ecs/src/lib.rs b/ecs/src/lib.rs
index 32ade13..667aa0e 100644
--- a/ecs/src/lib.rs
+++ b/ecs/src/lib.rs
@@ -20,6 +20,12 @@ use crate::component::{
Sequence as ComponentSequence,
};
use crate::entity::{Declaration as EntityDeclaration, Handle as EntityHandle};
+use crate::error::{
+ ErrorHandler,
+ Metadata as ErrorMetadata,
+ SourceKind as ErrorSourceKind,
+ err_handler_panic,
+};
use crate::event::component::Added;
use crate::event::{Emitted as EmittedEvent, NewEvents, Submitter as EventSubmitter};
use crate::extension::{Collector as ExtensionCollector, Extension};
@@ -50,6 +56,7 @@ use crate::uid::{Kind as UidKind, Uid};
pub mod actions;
pub mod component;
pub mod entity;
+pub mod error;
pub mod event;
pub mod extension;
pub mod pair;
@@ -74,6 +81,7 @@ pub struct World
data: WorldData,
stop: AtomicBool,
is_first_tick: AtomicBool,
+ error_handler: ErrorHandler,
}
impl World
@@ -85,6 +93,7 @@ impl World
data: WorldData::default(),
stop: AtomicBool::new(false),
is_first_tick: AtomicBool::new(false),
+ error_handler: err_handler_panic,
};
crate::phase::spawn_entities(&mut world);
@@ -94,6 +103,11 @@ impl World
world
}
+ pub fn set_err_handler(&mut self, err_handler: ErrorHandler)
+ {
+ self.error_handler = err_handler;
+ }
+
/// Creates a entity with the given components. A new unique [`Uid`] will be generated
/// for this entity.
pub fn create_entity<Comps>(&mut self, components: Comps) -> Uid
@@ -371,10 +385,20 @@ impl World
};
// SAFETY: The world lives long enough
- unsafe {
+ if let Err(err) = unsafe {
system
.system
- .run(self, SystemMetadata { ent_id: system_entity.uid() });
+ .run(self, SystemMetadata { ent_id: system_entity.uid() })
+ } {
+ cold_path();
+
+ (self.error_handler)(
+ err,
+ ErrorMetadata {
+ source_name: system.system.name(),
+ source_kind: ErrorSourceKind::System,
+ },
+ )
}
}
}
@@ -570,12 +594,22 @@ impl World
);
for (observer_ent_id, (observer,)) in query.iter_with_euids() {
- unsafe {
+ if let Err(err) = unsafe {
observer.run(
self,
SystemMetadata { ent_id: observer_ent_id },
emitted_event.clone(),
- );
+ )
+ } {
+ cold_path();
+
+ (self.error_handler)(
+ err,
+ ErrorMetadata {
+ source_name: observer.name(),
+ source_kind: ErrorSourceKind::Observer,
+ },
+ )
}
}
}