Skip to content

Commit

Permalink
Merge pull request #2356 from hannobraun/validation
Browse files Browse the repository at this point in the history
Add option to `ValidationConfig` that panics on the first error
  • Loading branch information
hannobraun committed May 15, 2024
2 parents 8df4a27 + 6dcc786 commit ae6c209
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/fj-core/src/layers/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ impl Command<Validation> for ValidateObject<'_> {
.validate(&state.config, &mut errors, self.geometry);

for err in errors {
if state.config.panic_on_error {
panic!("{:#?}", err);
}

events.push(ValidationFailed {
object: self.object.clone(),
err,
Expand Down
17 changes: 17 additions & 0 deletions crates/fj-core/src/validation/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ use fj_math::Scalar;
/// Configuration required for the validation process
#[derive(Debug, Clone, Copy)]
pub struct ValidationConfig {
/// Panic on first validation error, instead of storing it
///
/// Validation errors are usually stored in the validation layer, and only
/// cause a panic if the validation layer is dropped with unhandled errors.
///
/// This provides flexibility in handling validation errors, but can also be
/// helpful in understanding them, as experience has shown that the first
/// validation error often does not provide a full picture of what's wrong.
///
/// However, it can be helpful to get an immediate panic on a validation
/// error, to get the code that caused it into a stack trace. This is what
/// happens, if this option is set to `true`.
///
/// Defaults to `false`.
pub panic_on_error: bool,

/// The minimum distance between distinct objects
///
/// Objects whose distance is less than the value defined in this field, are
Expand All @@ -21,6 +37,7 @@ pub struct ValidationConfig {
impl Default for ValidationConfig {
fn default() -> Self {
Self {
panic_on_error: false,
distinct_min_distance: Scalar::from_f64(5e-7), // 0.5 µm,

// This value was chosen pretty arbitrarily. Seems small enough to
Expand Down

0 comments on commit ae6c209

Please sign in to comment.