use std::{collections::HashMap, error::Error, thread};
use crate::storage::ObjectId;
use super::{ValidationConfig, ValidationError};
#[derive(Default)]
pub struct Validation {
pub errors: HashMap<ObjectId, ValidationError>,
pub config: ValidationConfig,
}
impl Validation {
pub fn with_validation_config(config: ValidationConfig) -> Self {
let errors = HashMap::new();
Self { errors, config }
}
}
impl Drop for Validation {
fn drop(&mut self) {
let num_errors = self.errors.len();
if num_errors > 0 {
println!(
"Dropping `Validation` with {num_errors} unhandled validation \
errors:"
);
for err in self.errors.values() {
println!("{}", err);
let mut source = err.source();
while let Some(err) = source {
println!("\nCaused by:\n\t{err}");
source = err.source();
}
print!("\n\n");
}
if !thread::panicking() {
panic!();
}
}
}
}