jspg error refactoring checkpoint

This commit is contained in:
2026-06-23 17:03:27 -04:00
parent fb25224d22
commit d77765cb61
25 changed files with 362 additions and 218 deletions

View File

@ -1,4 +1,4 @@
use std::collections::HashSet;
use std::collections::{HashMap, HashSet};
use serde_json::Value;
@ -17,8 +17,11 @@ impl<'a> ValidationContext<'a> {
&& (arr.len() as f64) < min
{
result.errors.push(ValidationError {
code: "MIN_ITEMS".to_string(),
message: "Too few items".to_string(),
code: "MIN_ITEMS_VIOLATED".to_string(),
values: Some(HashMap::from([
("count".to_string(), arr.len().to_string()),
("limit".to_string(), min.to_string()),
])),
path: self.path.to_string(),
});
}
@ -26,8 +29,11 @@ impl<'a> ValidationContext<'a> {
&& (arr.len() as f64) > max
{
result.errors.push(ValidationError {
code: "MAX_ITEMS".to_string(),
message: "Too many items".to_string(),
code: "MAX_ITEMS_VIOLATED".to_string(),
values: Some(HashMap::from([
("count".to_string(), arr.len().to_string()),
("limit".to_string(), max.to_string()),
])),
path: self.path.to_string(),
});
}
@ -38,7 +44,7 @@ impl<'a> ValidationContext<'a> {
if seen.contains(&item) {
result.errors.push(ValidationError {
code: "UNIQUE_ITEMS_VIOLATED".to_string(),
message: "Array has duplicate items".to_string(),
values: None,
path: self.path.to_string(),
});
break;
@ -71,7 +77,10 @@ impl<'a> ValidationContext<'a> {
if _match_count < min {
result.errors.push(ValidationError {
code: "CONTAINS_VIOLATED".to_string(),
message: format!("Contains matches {} < min {}", _match_count, min),
values: Some(HashMap::from([
("count".to_string(), _match_count.to_string()),
("limit".to_string(), min.to_string()),
])),
path: self.path.to_string(),
});
}
@ -80,7 +89,10 @@ impl<'a> ValidationContext<'a> {
{
result.errors.push(ValidationError {
code: "CONTAINS_VIOLATED".to_string(),
message: format!("Contains matches {} > max {}", _match_count, max),
values: Some(HashMap::from([
("count".to_string(), _match_count.to_string()),
("limit".to_string(), max.to_string()),
])),
path: self.path.to_string(),
});
}