Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where validation errors could overwrite previous validation errors #2448

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions crates/fj-core/src/layers/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ impl Command<Validation> for ValidateObject<'_> {
panic!("{:#?}", err);
}

events.push(ValidationFailed {
object: self.object.clone(),
err,
});
events.push(ValidationFailed { err });
}
}
}
Expand All @@ -60,7 +57,7 @@ impl Command<Validation> for TakeErrors {
state: &Validation,
events: &mut Vec<Self::Event>,
) -> Self::Result {
let errors = ValidationErrors(state.errors.values().cloned().collect());
let errors = ValidationErrors(state.errors.to_vec());

events.push(self);

Expand All @@ -83,15 +80,12 @@ impl Event<Validation> for TakeErrors {
/// Event produced by `Layer<Validation>`.
#[derive(Clone)]
pub struct ValidationFailed {
/// The object for which validation failed
pub object: AnyObject<Stored>,

/// The validation error
pub err: ValidationError,
}

impl Event<Validation> for ValidationFailed {
fn evolve(&self, state: &mut Validation) {
state.errors.insert(self.object.id(), self.err.clone());
state.errors.push(self.err.clone());
}
}
10 changes: 4 additions & 6 deletions crates/fj-core/src/validation/validation.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
use std::{collections::HashMap, error::Error, thread};

use crate::storage::ObjectId;
use std::{error::Error, thread};

use super::{ValidationConfig, ValidationError};

/// Errors that occurred while validating the objects inserted into the stores
#[derive(Default)]
pub struct Validation {
/// All unhandled validation errors
pub errors: HashMap<ObjectId, ValidationError>,
pub errors: Vec<ValidationError>,

/// Validation configuration for the validation service
pub config: ValidationConfig,
Expand All @@ -17,7 +15,7 @@ pub struct Validation {
impl Validation {
/// Construct an instance of `Validation`, using the provided configuration
pub fn with_validation_config(config: ValidationConfig) -> Self {
let errors = HashMap::new();
let errors = Vec::new();
Self { errors, config }
}
}
Expand All @@ -31,7 +29,7 @@ impl Drop for Validation {
errors:"
);

for err in self.errors.values() {
for err in self.errors.iter() {
println!("{}", err);

// Once `Report` is stable, we can replace this:
Expand Down