mirror of
https://github.com/hannobraun/Fornjot
synced 2025-05-06 10:58:28 +00:00
Fix validation errors overwriting each other
Validation errors were stored by object ID, which made no sense. It wasn't necessary, but provided the possibility of a validation error overwriting a previous one that applied to the same object. On top of that, this change is a simplification, so a win all around.
This commit is contained in:
parent
a19143c87b
commit
be70a5330a
@ -60,7 +60,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);
|
||||
|
||||
@ -92,6 +92,6 @@ pub struct ValidationFailed {
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,4 @@
|
||||
use std::{collections::HashMap, error::Error, thread};
|
||||
|
||||
use crate::storage::ObjectId;
|
||||
use std::{error::Error, thread};
|
||||
|
||||
use super::{ValidationConfig, ValidationError};
|
||||
|
||||
@ -8,7 +6,7 @@ use super::{ValidationConfig, ValidationError};
|
||||
#[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,
|
||||
@ -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 }
|
||||
}
|
||||
}
|
||||
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user