fj_core/validation/
validation.rs1use std::{collections::HashMap, error::Error, thread};
2
3use crate::storage::ObjectId;
4
5use super::{ValidationConfig, ValidationError};
6
7#[derive(Default)]
9pub struct Validation {
10 pub errors: HashMap<ObjectId, ValidationError>,
12
13 pub config: ValidationConfig,
15}
16
17impl Validation {
18 pub fn with_validation_config(config: ValidationConfig) -> Self {
20 let errors = HashMap::new();
21 Self { errors, config }
22 }
23}
24
25impl Drop for Validation {
26 fn drop(&mut self) {
27 let num_errors = self.errors.len();
28 if num_errors > 0 {
29 println!(
30 "Dropping `Validation` with {num_errors} unhandled validation \
31 errors:"
32 );
33
34 for err in self.errors.values() {
35 println!("{}", err);
36
37 let mut source = err.source();
40 while let Some(err) = source {
41 println!("\nCaused by:\n\t{err}");
42 source = err.source();
43 }
44
45 print!("\n\n");
46 }
47
48 if !thread::panicking() {
49 panic!();
50 }
51 }
52 }
53}