diff --git a/crates/fj-kernel/src/services/mod.rs b/crates/fj-kernel/src/services/mod.rs index eb55c2a2d..a42373e82 100644 --- a/crates/fj-kernel/src/services/mod.rs +++ b/crates/fj-kernel/src/services/mod.rs @@ -15,7 +15,7 @@ use crate::objects::Objects; pub use self::{ objects::ServiceObjectsExt, service::{Service, State}, - validation::{Validation, ValidationEvent}, + validation::{Validation, ValidationFailed}, }; /// The kernel services diff --git a/crates/fj-kernel/src/services/validation.rs b/crates/fj-kernel/src/services/validation.rs index 321cfb26b..c3f8f9d4d 100644 --- a/crates/fj-kernel/src/services/validation.rs +++ b/crates/fj-kernel/src/services/validation.rs @@ -10,9 +10,7 @@ use super::{objects::ObjectToInsert, State}; /// Errors that occurred while validating the objects inserted into the stores #[derive(Default)] -pub struct Validation( - pub BTreeMap, ValidationError)>, -); +pub struct Validation(pub BTreeMap); impl Drop for Validation { fn drop(&mut self) { @@ -23,8 +21,8 @@ impl Drop for Validation { errors:" ); - for (_, err) in self.0.values() { - println!("{err}"); + for event in self.0.values() { + println!("{}", event.err); } if !thread::panicking() { @@ -36,32 +34,28 @@ impl Drop for Validation { impl State for Validation { type Command = ObjectToInsert; - type Event = ValidationEvent; + type Event = ValidationFailed; fn decide(&self, command: Self::Command, events: &mut Vec) { - let err = command.object.validate().err(); - events.push(ValidationEvent { - object: command.object.into(), - err, - }); + if let Err(err) = command.object.validate() { + events.push(ValidationFailed { + object: command.object.into(), + err, + }); + } } fn evolve(&mut self, event: &Self::Event) { - if let Some(err) = &event.err { - self.0 - .insert(event.object.id(), (event.object.clone(), err.clone())); - } + self.0.insert(event.object.id(), event.clone()); } } /// An event produced by the validation service #[derive(Clone)] -pub struct ValidationEvent { - /// The object for which validation has been attempted +pub struct ValidationFailed { + /// The object for which validation failed pub object: Object, - /// The validation error, if the validation resulted in one - /// - /// If this is `None`, the object has been validated successfully. - pub err: Option, + /// The validation error + pub err: ValidationError, }