Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

Commit 6ecd366

Browse files
authored
fix: Begin transaction foes not handle error (#1833)
1 parent cbdc3e8 commit 6ecd366

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

src/transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1774,7 +1774,7 @@ export class Transaction extends Dml {
17741774
} else if (!this._useInRunner) {
17751775
reqOpts.singleUseTransaction = this._options;
17761776
} else {
1777-
this.begin().then(() => this.commit(options, callback));
1777+
this.begin().then(() => this.commit(options, callback), callback);
17781778
return;
17791779
}
17801780

test/spanner.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3382,6 +3382,30 @@ describe('Spanner with mock server', () => {
33823382
}) as v1.BeginTransactionRequest;
33833383
assert.ok(beginTxnRequest, 'beginTransaction was called');
33843384
});
3385+
3386+
it('should throw error if begin transaction fails on blind commit', async () => {
3387+
const database = newTestDatabase();
3388+
const err = {
3389+
message: 'Test error',
3390+
} as MockError;
3391+
spannerMock.setExecutionTime(
3392+
spannerMock.beginTransaction,
3393+
SimulatedExecutionTime.ofError(err)
3394+
);
3395+
try {
3396+
await database.runTransactionAsync(async tx => {
3397+
tx.insert('foo', {id: 1, name: 'One'});
3398+
await tx.commit();
3399+
});
3400+
} catch (e) {
3401+
assert.strictEqual(
3402+
(e as ServiceError).message,
3403+
'2 UNKNOWN: Test error'
3404+
);
3405+
} finally {
3406+
await database.close();
3407+
}
3408+
});
33853409
});
33863410

33873411
describe('table', () => {

0 commit comments

Comments
 (0)