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

@ -5,7 +5,9 @@ pub mod cache;
use crate::database::Database;
use crate::database::r#type::Type;
use crate::drop::{Drop, Error, ErrorDetails};
use serde_json::Value;
use std::collections::HashMap;
use std::sync::Arc;
pub struct Merger {
@ -21,20 +23,22 @@ impl Merger {
}
}
pub fn merge(&self, schema_id: &str, data: Value) -> crate::drop::Drop {
pub fn merge(&self, schema_id: &str, data: Value) -> Drop {
let mut notifications_queue = Vec::new();
let target_schema = match self.db.schemas.get(schema_id) {
Some(s) => Arc::clone(&s),
None => {
return crate::drop::Drop::with_errors(vec![crate::drop::Error {
code: "MERGE_FAILED".to_string(),
message: format!("Unknown schema_id: {}", schema_id),
details: crate::drop::ErrorDetails {
return Drop::with_errors(vec![Error {
code: "SCHEMA_NOT_FOUND".to_string(),
values: Some(HashMap::from([
("schema".to_string(), schema_id.to_string()),
])),
details: ErrorDetails {
path: None,
cause: None,
context: Some(data),
schema: None,
schema: Some(schema_id.to_string()),
},
}]);
}
@ -72,10 +76,12 @@ impl Merger {
}
}
return crate::drop::Drop::with_errors(vec![crate::drop::Error {
return Drop::with_errors(vec![Error {
code: final_code,
message: final_message,
details: crate::drop::ErrorDetails {
values: Some(HashMap::from([
("error".to_string(), final_message),
])),
details: ErrorDetails {
path: None,
cause: final_cause,
context: None,
@ -88,10 +94,12 @@ impl Merger {
// Execute the globally collected, pre-ordered notifications last!
for notify_sql in notifications_queue {
if let Err(e) = self.db.execute(&notify_sql, None) {
return crate::drop::Drop::with_errors(vec![crate::drop::Error {
return Drop::with_errors(vec![Error {
code: "MERGE_FAILED".to_string(),
message: format!("Executor Error in pre-ordered notify: {:?}", e),
details: crate::drop::ErrorDetails {
values: Some(HashMap::from([
("error".to_string(), e.to_string()),
])),
details: ErrorDetails {
path: None,
cause: None,
context: None,