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,6 @@
use crate::database::Database;
use crate::drop::{Drop, Error, ErrorDetails};
use std::collections::HashMap;
use std::sync::Arc;
pub mod compiler;
@ -22,17 +24,19 @@ impl Queryer {
&self,
schema_id: &str,
filter: Option<&serde_json::Value>,
) -> crate::drop::Drop {
) -> Drop {
let filters_map = filter.and_then(|f| f.as_object());
// 1. Process filters into structured $op keys and linear values
let (filter_keys, args) = match self.parse_filter_entries(filters_map) {
Ok(res) => res,
Err(msg) => {
return crate::drop::Drop::with_errors(vec![crate::drop::Error {
return Drop::with_errors(vec![Error {
code: "FILTER_PARSE_FAILED".to_string(),
message: msg.clone(),
details: crate::drop::ErrorDetails {
values: Some(HashMap::from([
("error".to_string(), msg.clone()),
])),
details: ErrorDetails {
path: None, // filters apply to the root query
cause: Some(msg),
context: filter.cloned(),
@ -134,10 +138,12 @@ impl Queryer {
.insert(cache_key.to_string(), compiled_sql.clone());
Ok(compiled_sql)
}
Err(e) => Err(crate::drop::Drop::with_errors(vec![crate::drop::Error {
Err(e) => Err(Drop::with_errors(vec![Error {
code: "QUERY_COMPILATION_FAILED".to_string(),
message: e.clone(),
details: crate::drop::ErrorDetails {
values: Some(HashMap::from([
("error".to_string(), e.clone()),
])),
details: ErrorDetails {
path: None,
cause: Some(e),
context: None,
@ -152,29 +158,33 @@ impl Queryer {
schema_id: &str,
sql: &str,
args: Vec<serde_json::Value>,
) -> crate::drop::Drop {
) -> Drop {
match self.db.query(sql, Some(args)) {
Ok(serde_json::Value::Array(table)) => {
if table.is_empty() {
crate::drop::Drop::success_with_val(serde_json::Value::Null)
Drop::success_with_val(serde_json::Value::Null)
} else {
crate::drop::Drop::success_with_val(table.first().unwrap().clone())
Drop::success_with_val(table.first().unwrap().clone())
}
}
Ok(other) => crate::drop::Drop::with_errors(vec![crate::drop::Error {
Ok(other) => Drop::with_errors(vec![Error {
code: "QUERY_FAILED".to_string(),
message: format!("Expected array from generic query, got: {:?}", other),
details: crate::drop::ErrorDetails {
values: Some(HashMap::from([
("error".to_string(), format!("Expected array from generic query, got: {:?}", other)),
])),
details: ErrorDetails {
path: None,
cause: Some(format!("Expected array, got {}", other)),
context: Some(serde_json::json!([sql])),
schema: Some(schema_id.to_string()),
},
}]),
Err(e) => crate::drop::Drop::with_errors(vec![crate::drop::Error {
Err(e) => Drop::with_errors(vec![Error {
code: "QUERY_FAILED".to_string(),
message: format!("SPI error in queryer: {}", e),
details: crate::drop::ErrorDetails {
values: Some(HashMap::from([
("error".to_string(), e.to_string()),
])),
details: ErrorDetails {
path: None,
cause: Some(format!("SPI error in queryer: {}", e)),
context: Some(serde_json::json!([sql])),