better error dropping

This commit is contained in:
2026-03-16 19:39:24 -04:00
parent 507dc6d780
commit d8fc286e94
6 changed files with 51 additions and 11 deletions

View File

@ -25,6 +25,7 @@ impl DatabaseExecutor for SpiExecutor {
} }
Spi::connect(|client| { Spi::connect(|client| {
pgrx::notice!("JSPG_SQL: {}", sql);
match client.select(sql, Some(args_with_oid.len() as i64), &args_with_oid) { match client.select(sql, Some(args_with_oid.len() as i64), &args_with_oid) {
Ok(tup_table) => { Ok(tup_table) => {
let mut results = Vec::new(); let mut results = Vec::new();
@ -53,6 +54,7 @@ impl DatabaseExecutor for SpiExecutor {
} }
Spi::connect_mut(|client| { Spi::connect_mut(|client| {
pgrx::notice!("JSPG_SQL: {}", sql);
match client.update(sql, Some(args_with_oid.len() as i64), &args_with_oid) { match client.update(sql, Some(args_with_oid.len() as i64), &args_with_oid) {
Ok(_) => Ok(()), Ok(_) => Ok(()),
Err(e) => Err(format!("SPI Execution Failure: {}", e)), Err(e) => Err(format!("SPI Execution Failure: {}", e)),

View File

@ -67,6 +67,10 @@ pub struct Error {
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ErrorDetails { pub struct ErrorDetails {
pub path: String, pub path: String,
// Extensions can be added here (package, cause, etc) #[serde(skip_serializing_if = "Option::is_none")]
// For now, validator only provides path pub cause: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub context: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub schema: Option<String>,
} }

View File

@ -31,6 +31,9 @@ fn jspg_failure() -> JsonB {
message: "JSPG extension has not been initialized via jspg_setup".to_string(), message: "JSPG extension has not been initialized via jspg_setup".to_string(),
details: crate::drop::ErrorDetails { details: crate::drop::ErrorDetails {
path: "".to_string(), path: "".to_string(),
cause: None,
context: None,
schema: None,
}, },
}; };
let drop = crate::drop::Drop::with_errors(vec![error]); let drop = crate::drop::Drop::with_errors(vec![error]);

View File

@ -36,6 +36,9 @@ impl Merger {
message: msg, message: msg,
details: crate::drop::ErrorDetails { details: crate::drop::ErrorDetails {
path: "".to_string(), path: "".to_string(),
cause: None,
context: None,
schema: None,
}, },
}]); }]);
} }
@ -49,6 +52,9 @@ impl Merger {
message: format!("Executor Error in pre-ordered notify: {:?}", e), message: format!("Executor Error in pre-ordered notify: {:?}", e),
details: crate::drop::ErrorDetails { details: crate::drop::ErrorDetails {
path: "".to_string(), path: "".to_string(),
cause: None,
context: None,
schema: None,
}, },
}]); }]);
} }

View File

@ -32,9 +32,12 @@ impl Queryer {
Err(msg) => { Err(msg) => {
return crate::drop::Drop::with_errors(vec![crate::drop::Error { return crate::drop::Drop::with_errors(vec![crate::drop::Error {
code: "FILTER_PARSE_FAILED".to_string(), code: "FILTER_PARSE_FAILED".to_string(),
message: msg, message: msg.clone(),
details: crate::drop::ErrorDetails { details: crate::drop::ErrorDetails {
path: schema_id.to_string(), path: "".to_string(), // filters apply to the root query
cause: Some(msg),
context: filters.map(|f| vec![f.to_string()]),
schema: Some(schema_id.to_string()),
}, },
}]); }]);
} }
@ -104,9 +107,12 @@ impl Queryer {
} }
Err(e) => Err(crate::drop::Drop::with_errors(vec![crate::drop::Error { Err(e) => Err(crate::drop::Drop::with_errors(vec![crate::drop::Error {
code: "QUERY_COMPILATION_FAILED".to_string(), code: "QUERY_COMPILATION_FAILED".to_string(),
message: e, message: e.clone(),
details: crate::drop::ErrorDetails { details: crate::drop::ErrorDetails {
path: schema_id.to_string(), path: "".to_string(),
cause: Some(e),
context: None,
schema: Some(schema_id.to_string()),
}, },
}])), }])),
} }
@ -130,14 +136,20 @@ impl Queryer {
code: "QUERY_FAILED".to_string(), code: "QUERY_FAILED".to_string(),
message: format!("Expected array from generic query, got: {:?}", other), message: format!("Expected array from generic query, got: {:?}", other),
details: crate::drop::ErrorDetails { details: crate::drop::ErrorDetails {
path: schema_id.to_string(), path: "".to_string(),
cause: Some(format!("Expected array, got {}", other)),
context: Some(vec![sql.to_string()]),
schema: Some(schema_id.to_string()),
}, },
}]), }]),
Err(e) => crate::drop::Drop::with_errors(vec![crate::drop::Error { Err(e) => crate::drop::Drop::with_errors(vec![crate::drop::Error {
code: "QUERY_FAILED".to_string(), code: "QUERY_FAILED".to_string(),
message: format!("SPI error in queryer: {}", e), message: format!("SPI error in queryer: {}", e),
details: crate::drop::ErrorDetails { details: crate::drop::ErrorDetails {
path: schema_id.to_string(), path: "".to_string(),
cause: Some(format!("SPI error in queryer: {}", e)),
context: Some(vec![sql.to_string()]),
schema: Some(schema_id.to_string()),
}, },
}]), }]),
} }

View File

@ -67,7 +67,12 @@ impl Validator {
.map(|e| crate::drop::Error { .map(|e| crate::drop::Error {
code: e.code, code: e.code,
message: e.message, message: e.message,
details: crate::drop::ErrorDetails { path: e.path }, details: crate::drop::ErrorDetails {
path: e.path,
cause: None,
context: None,
schema: None,
},
}) })
.collect(); .collect();
crate::drop::Drop::with_errors(errors) crate::drop::Drop::with_errors(errors)
@ -76,7 +81,12 @@ impl Validator {
Err(e) => crate::drop::Drop::with_errors(vec![crate::drop::Error { Err(e) => crate::drop::Drop::with_errors(vec![crate::drop::Error {
code: e.code, code: e.code,
message: e.message, message: e.message,
details: crate::drop::ErrorDetails { path: e.path }, details: crate::drop::ErrorDetails {
path: e.path,
cause: None,
context: None,
schema: None,
},
}]), }]),
} }
} else { } else {
@ -84,7 +94,10 @@ impl Validator {
code: "SCHEMA_NOT_FOUND".to_string(), code: "SCHEMA_NOT_FOUND".to_string(),
message: format!("Schema {} not found", schema_id), message: format!("Schema {} not found", schema_id),
details: crate::drop::ErrorDetails { details: crate::drop::ErrorDetails {
path: "".to_string(), path: "/".to_string(),
cause: None,
context: None,
schema: None,
}, },
}]) }])
} }