Compare commits

...

4 Commits

Author SHA1 Message Date
ebb97b3509 version: 1.0.69 2026-03-16 21:21:25 -04:00
5d18847f32 pgrx try catch 2026-03-16 21:21:11 -04:00
4a33e29628 version: 1.0.68 2026-03-16 19:39:34 -04:00
d8fc286e94 better error dropping 2026-03-16 19:39:24 -04:00
7 changed files with 81 additions and 27 deletions

View File

@ -24,20 +24,28 @@ impl DatabaseExecutor for SpiExecutor {
}
}
Spi::connect(|client| {
match client.select(sql, Some(args_with_oid.len() as i64), &args_with_oid) {
Ok(tup_table) => {
let mut results = Vec::new();
for row in tup_table {
if let Ok(Some(jsonb)) = row.get::<pgrx::JsonB>(1) {
results.push(jsonb.0);
pgrx::PgTryBuilder::new(|| {
Spi::connect(|client| {
pgrx::notice!("JSPG_SQL: {}", sql);
match client.select(sql, Some(args_with_oid.len() as i64), &args_with_oid) {
Ok(tup_table) => {
let mut results = Vec::new();
for row in tup_table {
if let Ok(Some(jsonb)) = row.get::<pgrx::JsonB>(1) {
results.push(jsonb.0);
}
}
Ok(Value::Array(results))
}
Ok(Value::Array(results))
Err(e) => Err(format!("SPI Query Fetch Failure: {}", e)),
}
Err(e) => Err(format!("SPI Query Fetch Failure: {}", e)),
}
})
})
.catch_others(|cause| {
pgrx::warning!("JSPG Caught Native Postgres Error: {:?}", cause);
Err(format!("{:?}", cause))
})
.execute()
}
fn execute(&self, sql: &str, args: Option<&[Value]>) -> Result<(), String> {
@ -52,12 +60,20 @@ impl DatabaseExecutor for SpiExecutor {
}
}
Spi::connect_mut(|client| {
match client.update(sql, Some(args_with_oid.len() as i64), &args_with_oid) {
Ok(_) => Ok(()),
Err(e) => Err(format!("SPI Execution Failure: {}", e)),
}
pgrx::PgTryBuilder::new(|| {
Spi::connect_mut(|client| {
pgrx::notice!("JSPG_SQL: {}", sql);
match client.update(sql, Some(args_with_oid.len() as i64), &args_with_oid) {
Ok(_) => Ok(()),
Err(e) => Err(format!("SPI Execution Failure: {}", e)),
}
})
})
.catch_others(|cause| {
pgrx::warning!("JSPG Caught Native Postgres Error: {:?}", cause);
Err(format!("{:?}", cause))
})
.execute()
}
fn auth_user_id(&self) -> Result<String, String> {

View File

@ -67,6 +67,10 @@ pub struct Error {
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ErrorDetails {
pub path: String,
// Extensions can be added here (package, cause, etc)
// For now, validator only provides path
#[serde(skip_serializing_if = "Option::is_none")]
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(),
details: crate::drop::ErrorDetails {
path: "".to_string(),
cause: None,
context: None,
schema: None,
},
};
let drop = crate::drop::Drop::with_errors(vec![error]);

View File

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

View File

@ -32,9 +32,12 @@ impl Queryer {
Err(msg) => {
return crate::drop::Drop::with_errors(vec![crate::drop::Error {
code: "FILTER_PARSE_FAILED".to_string(),
message: msg,
message: msg.clone(),
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 {
code: "QUERY_COMPILATION_FAILED".to_string(),
message: e,
message: e.clone(),
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(),
message: format!("Expected array from generic query, got: {:?}", other),
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 {
code: "QUERY_FAILED".to_string(),
message: format!("SPI error in queryer: {}", e),
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 {
code: e.code,
message: e.message,
details: crate::drop::ErrorDetails { path: e.path },
details: crate::drop::ErrorDetails {
path: e.path,
cause: None,
context: None,
schema: None,
},
})
.collect();
crate::drop::Drop::with_errors(errors)
@ -76,7 +81,12 @@ impl Validator {
Err(e) => crate::drop::Drop::with_errors(vec![crate::drop::Error {
code: e.code,
message: e.message,
details: crate::drop::ErrorDetails { path: e.path },
details: crate::drop::ErrorDetails {
path: e.path,
cause: None,
context: None,
schema: None,
},
}]),
}
} else {
@ -84,7 +94,10 @@ impl Validator {
code: "SCHEMA_NOT_FOUND".to_string(),
message: format!("Schema {} not found", schema_id),
details: crate::drop::ErrorDetails {
path: "".to_string(),
path: "/".to_string(),
cause: None,
context: None,
schema: None,
},
}])
}

View File

@ -1 +1 @@
1.0.67
1.0.69