Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eb25f8489e | |||
| 21937db8de |
4
.env
4
.env
@ -1,7 +1,7 @@
|
|||||||
ENVIRONMENT=local
|
ENVIRONMENT=local
|
||||||
DATABASE_PASSWORD=QgSvstSjoc6fKphMzNgT3SliNY10eSRS
|
DATABASE_PASSWORD=tIr4TJ0qUwGVM0rlQSe3W7Tgpi33zPbk
|
||||||
DATABASE_ROLE=agreego_admin
|
DATABASE_ROLE=agreego_admin
|
||||||
DATABASE_HOST=127.1.27.9
|
DATABASE_HOST=127.1.27.4
|
||||||
DATABASE_PORT=5432
|
DATABASE_PORT=5432
|
||||||
POSTGRES_PASSWORD=xzIq5JT0xY3F+2m1GtnrKDdK29sNSXVVYZHPKJVh8pI=
|
POSTGRES_PASSWORD=xzIq5JT0xY3F+2m1GtnrKDdK29sNSXVVYZHPKJVh8pI=
|
||||||
DATABASE_NAME=agreego
|
DATABASE_NAME=agreego
|
||||||
|
|||||||
24
src/lib.rs
24
src/lib.rs
@ -48,22 +48,24 @@ fn cache_json_schema(schema_id: &str, schema: JsonB) -> JsonB {
|
|||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
let error = match &e {
|
let error = match &e {
|
||||||
CompileError::ValidationError { url: _url, src } => { // Prefix url with _
|
CompileError::ValidationError { url: _url, src } => {
|
||||||
json!({
|
// Collect leaf errors from the meta-schema validation failure
|
||||||
"message": format!("Schema '{}' failed validation against its metaschema: {}", schema_id, src),
|
let mut error_list = Vec::new();
|
||||||
"schema_path": schema_path,
|
collect_leaf_errors(src, &mut error_list);
|
||||||
"error": format!("{:?}", src),
|
// Return the flat list directly
|
||||||
})
|
json!(error_list)
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let _error_type = format!("{:?}", e).split('(').next().unwrap_or("Unknown").to_string(); // Prefix error_type with _
|
// Keep existing handling for other compilation errors
|
||||||
|
let _error_type = format!("{:?}", e).split('(').next().unwrap_or("Unknown").to_string();
|
||||||
json!({
|
json!({
|
||||||
"message": format!("Schema '{}' compilation failed: {}", schema_id, e),
|
"message": format!("Schema '{}' compilation failed: {}", schema_id, e),
|
||||||
"schema_path": schema_path,
|
"schema_path": schema_path,
|
||||||
"error": format!("{:?}", e),
|
"detail": format!("{:?}", e),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// Ensure the outer structure remains { success: false, error: ... }
|
||||||
JsonB(json!({
|
JsonB(json!({
|
||||||
"success": false,
|
"success": false,
|
||||||
"error": error
|
"error": error
|
||||||
@ -91,11 +93,11 @@ fn validate_json_schema(schema_id: &str, instance: JsonB) -> JsonB {
|
|||||||
Err(validation_error) => {
|
Err(validation_error) => {
|
||||||
// Directly use the result of format_validation_error
|
// Directly use the result of format_validation_error
|
||||||
// which now includes the top-level success indicator and flat error list
|
// which now includes the top-level success indicator and flat error list
|
||||||
let mut all_errors = Vec::new();
|
let mut error_list = Vec::new();
|
||||||
collect_leaf_errors(&validation_error, &mut all_errors);
|
collect_leaf_errors(&validation_error, &mut error_list);
|
||||||
JsonB(json!({
|
JsonB(json!({
|
||||||
"success": false,
|
"success": false,
|
||||||
"error": all_errors // Flat list of specific errors
|
"error": error_list // Flat list of specific errors
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
36
src/tests.rs
36
src/tests.rs
@ -251,26 +251,24 @@ fn test_cache_invalid_json_schema() {
|
|||||||
|
|
||||||
let cache_result = cache_json_schema(schema_id, jsonb(invalid_schema));
|
let cache_result = cache_json_schema(schema_id, jsonb(invalid_schema));
|
||||||
|
|
||||||
// Manually check the structure for cache_json_schema failure
|
// Expect 2 leaf errors because the meta-schema validation fails at the type value
|
||||||
let json_result = &cache_result.0;
|
// and within the type array itself.
|
||||||
let success = json_result.get("success").and_then(Value::as_bool);
|
assert_failure_with_json!(
|
||||||
let error_obj = json_result.get("error").and_then(Value::as_object);
|
cache_result,
|
||||||
|
2, // Expect exactly two leaf errors
|
||||||
|
"value must be one of", // Check message substring (present in both)
|
||||||
|
"Caching invalid schema should fail with specific meta-schema validation errors."
|
||||||
|
);
|
||||||
|
|
||||||
if success != Some(false) {
|
// Ensure the error is an array and check specifics
|
||||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
let error_array = cache_result.0["error"].as_array().expect("Error field should be an array");
|
||||||
panic!("Assertion Failed (expected failure, success was not false): Caching invalid schema should fail.\nResult JSON:\n{}", pretty_json);
|
assert_eq!(error_array.len(), 2);
|
||||||
}
|
// Note: Order might vary depending on boon's internal processing, check both possibilities or sort.
|
||||||
if error_obj.is_none() {
|
// Assuming the order shown in the logs for now:
|
||||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
assert_eq!(error_array[0]["instance_path"], "/type");
|
||||||
panic!("Assertion Failed (expected 'error' object, but none found): Caching invalid schema should return an error object.\nResult JSON:\n{}", pretty_json);
|
assert!(error_array[0]["message"].as_str().unwrap().contains("value must be one of"));
|
||||||
}
|
assert_eq!(error_array[1]["instance_path"], "/type/0");
|
||||||
// Check specific fields within the error object
|
assert!(error_array[1]["message"].as_str().unwrap().contains("value must be one of"));
|
||||||
let message = error_obj.unwrap().get("message").and_then(Value::as_str);
|
|
||||||
// Updated check based on the actual error message seen in the logs
|
|
||||||
if message.map_or(true, |m| !m.contains("failed validation against its metaschema") || !m.contains("/type/0': value must be one of")) {
|
|
||||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
|
||||||
panic!("Assertion Failed (error message mismatch): Expected metaschema validation failure message containing '/type/0' error detail.\nResult JSON:\n{}", pretty_json);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pg_test]
|
#[pg_test]
|
||||||
|
|||||||
Reference in New Issue
Block a user