Skip to content

Commit

Permalink
Add Layer<Validation>::take_errors
Browse files Browse the repository at this point in the history
It is an improvement over `into_result` as it doesn't require dropping
the validation layer.
  • Loading branch information
hannobraun committed Feb 15, 2024
1 parent 61ad7ba commit 5fbc34c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions crates/fj-core/src/layers/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ use crate::{
use super::{objects::InsertObject, Command, Event, Layer};

impl Layer<Validation> {
/// Take all errors stored in the validation layer
pub fn take_errors(&mut self) -> Result<(), ValidationErrors> {
self.process(TakeErrors, &mut Vec::new())
}

/// Consume the validation layer, returning any validation errors
pub fn into_result(self) -> Result<(), ValidationErrors> {
let errors = self.into_state().into_errors();
Expand Down
8 changes: 4 additions & 4 deletions crates/fj-core/src/validate/solid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ mod tests {
valid_solid.validate_and_return_first_error()?;

// Ignore remaining validation errors.
let _ = core.layers.validation.into_result();
let _ = core.layers.validation.take_errors();

Ok(())
}
Expand Down Expand Up @@ -289,7 +289,7 @@ mod tests {
valid_solid.validate_and_return_first_error()?;

// Ignore remaining validation errors.
let _ = core.layers.validation.into_result();
let _ = core.layers.validation.take_errors();

Ok(())
}
Expand Down Expand Up @@ -339,7 +339,7 @@ mod tests {
valid_solid.validate_and_return_first_error()?;

// Ignore remaining validation errors.
let _ = core.layers.validation.into_result();
let _ = core.layers.validation.take_errors();

Ok(())
}
Expand Down Expand Up @@ -379,7 +379,7 @@ mod tests {
valid_solid.validate_and_return_first_error()?;

// Ignore remaining validation errors.
let _ = core.layers.validation.into_result();
let _ = core.layers.validation.take_errors();

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions crates/fj/src/handle_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::Args;
///
/// This function is used by Fornjot's own testing infrastructure, but is useful
/// beyond that, when using Fornjot directly to define a model.
pub fn handle_model<M>(model: &M, core: Instance) -> Result
pub fn handle_model<M>(model: &M, mut core: Instance) -> Result
where
for<'r> (&'r M, Tolerance): Triangulate,
M: BoundingVolume<3>,
Expand All @@ -36,7 +36,7 @@ where
let args = Args::parse();

if !args.ignore_validation {
core.layers.validation.into_result()?;
core.layers.validation.take_errors()?;
}

let aabb = model.aabb().unwrap_or(Aabb {
Expand Down

0 comments on commit 5fbc34c

Please sign in to comment.