diff --git a/crates/fj-core/src/services/mod.rs b/crates/fj-core/src/services/mod.rs index 71c3310d2f..ee3c485397 100644 --- a/crates/fj-core/src/services/mod.rs +++ b/crates/fj-core/src/services/mod.rs @@ -6,7 +6,10 @@ mod objects; mod service; mod validation; -use crate::objects::{Object, ObjectSet, Objects, WithHandle}; +use crate::{ + objects::{Object, ObjectSet, Objects, WithHandle}, + validate::ValidationErrors, +}; pub use self::{ objects::{InsertObject, Operation}, @@ -61,6 +64,19 @@ impl Services { self.validation .execute(ValidationCommand::OnlyValidate { objects }, &mut events); } + + /// Drop `Services`; return any unhandled validation error + pub fn drop_and_validate(self) -> Result<(), ValidationErrors> { + let errors = ValidationErrors( + self.validation.errors.values().cloned().collect(), + ); + + if errors.0.is_empty() { + Ok(()) + } else { + Err(errors) + } + } } impl Default for Services {