Skip to content

typescript.transaction_boundary

Correctness High

Detects multiple database operations that should be wrapped in transactions.

Missing transactions:

  • Partial updates — Some ops succeed, others fail
  • Data corruption — Inconsistent state
  • Lost data — No rollback on failure
// ❌ 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();
}
}
  • Multiple INSERT/UPDATE in same function without tx
  • Missing BEGIN/COMMIT pairs
  • Money/inventory operations without atomicity

Unfault can wrap operations in a transaction.