Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/packages/dumbo/src/core/connections/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ export const executeInTransaction = async <

return result;
} catch (e) {
await transaction.rollback();
try {
await transaction.rollback();
} catch {
// rollback failed — preserve the original error
}
throw e;
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import assert from 'assert';
import { describe, it } from 'vitest';
import { sqlite3Connection } from '..';
import { JSONSerializer, SQL } from '../../../../core';
import { InMemorySQLiteDatabase } from '../../core';

describe('withTransaction error preservation', () => {
it('should surface the original callback error, not the rollback error', async () => {
const connection = sqlite3Connection({
fileName: InMemorySQLiteDatabase,
serializer: JSONSerializer,
});

try {
try {
await connection.withTransaction(async (tx) => {
await tx.execute.command(
SQL`CREATE TABLE IF NOT EXISTS test_error (id INTEGER, value TEXT)`,
);

// Close the underlying database to cause rollback to fail
await connection.close();

throw new Error('original callback error');
});
assert.fail('should have thrown');
} catch (err) {
assert.strictEqual(
(err instanceof Error ? err.message : String(err)),
'original callback error',
);
}
} finally {
try {
await connection.close();
} catch {
// connection may already be closed
}
}
});
});