Skip to content

Commit 5a9803f

Browse files
committed
Adjust error thrown
1 parent 458ba32 commit 5a9803f

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

packages/core/src/transaction.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,15 @@ class Transaction {
291291
}
292292
}
293293

294-
_onErrorCallback (error: Error): Promise<Connection | null> {
294+
_onErrorCallback (): Promise<Connection | null> {
295295
// error will be "acknowledged" by sending a RESET message
296296
// database will then forget about this transaction and cleanup all corresponding resources
297297
// it is thus safe to move this transaction to a FAILED state and disallow any further interactions with it
298298
this._state = _states.FAILED
299299
this._onClose()
300+
const error = newError(
301+
'Cannot interact with this result, because transaction has been rolled back either because of an error.'
302+
)
300303
this._results.forEach(result => {
301304
if (result.isOpen()) {
302305
// @ts-expect-error

packages/core/test/transaction.test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ testTx('TransactionPromise', newTransactionPromise, () => {
217217

218218
try {
219219
await tx.commit()
220-
fail('shoud not succeed')
220+
fail('should not succeed')
221221
} catch (e) {
222222
expect(e).toEqual(newError(
223223
'Cannot commit this transaction, because it has been rolled back either because of an error or explicit termination.'
@@ -397,6 +397,9 @@ function testTx<T extends Transaction> (transactionName: string, newTransaction:
397397
it('should cascade errors in a result to other open results', async () => {
398398
const connection = newFakeConnection()
399399
const expectedError = newError('Something right is not wrong, wut?')
400+
const expectedTerminationError = newError(
401+
'Cannot interact with this result, because transaction has been rolled back either because of an error.'
402+
)
400403
const tx = newTransaction({
401404
connection,
402405
fetchSize: 1000,
@@ -430,8 +433,8 @@ function testTx<T extends Transaction> (transactionName: string, newTransaction:
430433
const brokenResult = tx.run('should error')
431434

432435
await expect(brokenResult).rejects.toThrowError(expectedError)
433-
await expect(nonConsumedResult).rejects.toThrowError(expectedError)
434-
expect(observers[0].error).toEqual(expectedError)
436+
await expect(nonConsumedResult).rejects.toThrowError(expectedTerminationError)
437+
expect(observers[0].error).toEqual(expectedTerminationError)
435438
expect(observers[1].error).not.toBeDefined()
436439
expect(observers[2].error).toEqual(expectedError)
437440
})

packages/core/test/utils/result-stream-observer.mock.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ export default class ResultStreamObserverMock implements observer.ResultStreamOb
9595
}
9696

9797
onError (error: Error): void {
98+
if (this._error != null) {
99+
// The implementation of stream observer
100+
// ignores errors happens after an error occurs.
101+
return
102+
}
98103
this._error = error
99104
if (this._beforeError != null) {
100105
this._beforeError(error)

packages/neo4j-driver-deno/lib/core/transaction.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,18 @@ class Transaction {
291291
}
292292
}
293293

294-
_onErrorCallback (error: Error): Promise<Connection | null> {
294+
_onErrorCallback (): Promise<Connection | null> {
295295
// error will be "acknowledged" by sending a RESET message
296296
// database will then forget about this transaction and cleanup all corresponding resources
297297
// it is thus safe to move this transaction to a FAILED state and disallow any further interactions with it
298298
this._state = _states.FAILED
299299
this._onClose()
300+
const error = newError(
301+
'Cannot interact with this result, because transaction has been rolled back either because of an error.'
302+
)
300303
this._results.forEach(result => {
301304
if (result.isOpen()) {
302-
// @ts-expect-error
305+
// @ts-expect-error
303306
result._streamObserverPromise
304307
.then(resultStreamObserver => resultStreamObserver.onError(error))
305308
// Nothing to do since we don't have a observer to notify the error

0 commit comments

Comments
 (0)