typescript.transaction_boundary
Correctness
High
Detects multiple database operations that should be wrapped in transactions.
Why It Matters
Section titled “Why It Matters”Missing transactions:
- Partial updates — Some ops succeed, others fail
- Data corruption — Inconsistent state
- Lost data — No rollback on failure
Example
Section titled “Example”// ❌ Before (no transaction)async function transferFunds(from: string, to: string, amount: number) { await db.query('UPDATE accounts SET balance = balance - $1 WHERE id = $2', [amount, from]); await db.query('UPDATE accounts SET balance = balance + $1 WHERE id = $2', [amount, to]); // If second query fails, money vanishes!}// ✅ After (with transaction)async function transferFunds(from: string, to: string, amount: number) { const client = await db.connect(); try { await client.query('BEGIN'); await client.query('UPDATE accounts SET balance = balance - $1 WHERE id = $2', [amount, from]); await client.query('UPDATE accounts SET balance = balance + $1 WHERE id = $2', [amount, to]); await client.query('COMMIT'); } catch (e) { await client.query('ROLLBACK'); throw e; } finally { client.release(); }}What Unfault Detects
Section titled “What Unfault Detects”- Multiple INSERT/UPDATE in same function without tx
- Missing BEGIN/COMMIT pairs
- Money/inventory operations without atomicity
Auto-Fix
Section titled “Auto-Fix”Unfault can wrap operations in a transaction.