Verbessere Fehlerbehandlung in SQL-Abfragen: Füge detaillierte Fehlermeldungen für Vorbereitungs- und Ausführungsfehler in den Director- und Politics-Workern hinzu.

This commit is contained in:
Torsten Schulz (local)
2025-12-16 08:52:08 +01:00
parent b45990c1b6
commit 74fee2d4c9
4 changed files with 88 additions and 36 deletions

View File

@@ -740,13 +740,17 @@ impl DirectorWorker {
// Default
let mut cumulative_tax_percent = DEFAULT_TAX_PERCENT;
conn.prepare("get_branch_region", QUERY_GET_BRANCH_REGION)?;
let branch_rows = conn.execute("get_branch_region", &[&branch_id])?;
conn.prepare("get_branch_region", QUERY_GET_BRANCH_REGION)
.map_err(|e| DbError::new(format!("[DirectorWorker] prepare get_branch_region: {e}")))?;
let branch_rows = conn.execute("get_branch_region", &[&branch_id])
.map_err(|e| DbError::new(format!("[DirectorWorker] exec get_branch_region branch_id={}: {e}", branch_id)))?;
let branch_region_id: Option<i32> = branch_rows.first().and_then(|r| r.get("region_id")).and_then(|v| v.parse().ok());
if let Some(region_id) = branch_region_id {
conn.prepare("get_user_offices", QUERY_GET_USER_OFFICES)?;
let offices = conn.execute("get_user_offices", &[&user_id])?;
conn.prepare("get_user_offices", QUERY_GET_USER_OFFICES)
.map_err(|e| DbError::new(format!("[DirectorWorker] prepare get_user_offices: {e}")))?;
let offices = conn.execute("get_user_offices", &[&user_id])
.map_err(|e| DbError::new(format!("[DirectorWorker] exec get_user_offices user_id={}: {e}", user_id)))?;
let mut exempt_types: Vec<String> = Vec::new();
let mut has_chancellor = false;
@@ -768,17 +772,21 @@ impl DirectorWorker {
}
if exempt_types.is_empty() {
conn.prepare("cumulative_tax_no_exempt", QUERY_CUMULATIVE_TAX_NO_EXEMPT)?;
let res = conn.execute("cumulative_tax_no_exempt", &[&region_id])?;
conn.prepare("cumulative_tax_no_exempt", QUERY_CUMULATIVE_TAX_NO_EXEMPT)
.map_err(|e| DbError::new(format!("[DirectorWorker] prepare cumulative_tax_no_exempt: {e}")))?;
let res = conn.execute("cumulative_tax_no_exempt", &[&region_id])
.map_err(|e| DbError::new(format!("[DirectorWorker] exec cumulative_tax_no_exempt region_id={}: {e}", region_id)))?;
if let Some(row) = res.first()
&& let Some(tp) = row.get("total_percent")
{
cumulative_tax_percent = tp.parse::<f64>().unwrap_or(DEFAULT_TAX_PERCENT);
}
} else {
conn.prepare("cumulative_tax_with_exempt", QUERY_CUMULATIVE_TAX_WITH_EXEMPT)?;
conn.prepare("cumulative_tax_with_exempt", QUERY_CUMULATIVE_TAX_WITH_EXEMPT)
.map_err(|e| DbError::new(format!("[DirectorWorker] prepare cumulative_tax_with_exempt: {e}")))?;
let exempt_array: Vec<&str> = exempt_types.iter().map(|s| s.as_str()).collect();
let res = conn.execute("cumulative_tax_with_exempt", &[&region_id, &exempt_array])?;
let res = conn.execute("cumulative_tax_with_exempt", &[&region_id, &exempt_array])
.map_err(|e| DbError::new(format!("[DirectorWorker] exec cumulative_tax_with_exempt region_id={} exempt={:?}: {}", region_id, exempt_array, e)))?;
if let Some(row) = res.first() && let Some(tp) = row.get("total_percent") {
cumulative_tax_percent = tp.parse::<f64>().unwrap_or(DEFAULT_TAX_PERCENT);
}