mirror of
https://github.com/sortedcord/alemno-payments.git
synced 2026-07-22 04:02:49 +05:30
feat: Add resilience hardening for csv parser
This commit is contained in:
@@ -75,14 +75,24 @@ def parse_and_validate_csv(content: bytes) -> List[Dict[str, Any]]:
|
||||
else None
|
||||
)
|
||||
|
||||
if not all([txn_id, date_str, amount_str, merchant]):
|
||||
if not all([date_str, amount_str, merchant]):
|
||||
raise InvalidCSVException(
|
||||
f"Row {line_num}: Empty values are not allowed in required fields"
|
||||
f"Row {line_num}: Empty values are not allowed in required fields (date, amount, merchant)"
|
||||
)
|
||||
|
||||
# Auto-generate txn_id if missing or empty
|
||||
if not txn_id or not txn_id.strip():
|
||||
import uuid
|
||||
txn_id = f"GEN_{uuid.uuid4().hex[:8].upper()}"
|
||||
else:
|
||||
txn_id = txn_id.strip()
|
||||
|
||||
# Validate amount
|
||||
cleaned_amount_str = (
|
||||
amount_str.strip().replace("$", "").replace("₹", "").replace(",", "")
|
||||
)
|
||||
try:
|
||||
amount = float(amount_str.strip())
|
||||
amount = float(cleaned_amount_str)
|
||||
except ValueError as e:
|
||||
raise InvalidCSVException(
|
||||
f"Row {line_num}: Invalid amount '{amount_str}'. Must be a number."
|
||||
|
||||
Reference in New Issue
Block a user