Skip to content

Commit 1e1e517

Browse files
authored
Improve error logging during ChannelConnection._handleFatalError (#812)
1 parent 28532f4 commit 1e1e517

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

packages/bolt-connection/src/connection/connection-channel.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ export default class ChannelConnection extends Connection {
277277

278278
if (this._log.isErrorEnabled()) {
279279
this._log.error(
280-
`experienced a fatal error ${json.stringify(this._error)}`
280+
`experienced a fatal error caused by ${this._error} (${json.stringify(this._error)})`
281281
)
282282
}
283283

packages/bolt-connection/test/connection/connection-channel.test.js

+28-4
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ describe('ChannelConnection', () => {
129129
describe('._handleFatalError()', () => {
130130
describe('when there is not current failure on going', () => {
131131
const thrownError = newError('some error', 'C')
132+
let loggerFunction;
132133
let notifyFatalError;
133134
let connection;
134135

@@ -138,9 +139,10 @@ describe('ChannelConnection', () => {
138139
notifyFatalError,
139140
currentFailure: null
140141
}
141-
142+
loggerFunction = jest.fn()
143+
const logger = new Logger('info', loggerFunction)
142144
const protocolSupplier = () => protocol
143-
connection = spyOnConnectionChannel({ protocolSupplier })
145+
connection = spyOnConnectionChannel({ protocolSupplier, logger })
144146
})
145147

146148
it('should set connection state to broken', () => {
@@ -160,11 +162,22 @@ describe('ChannelConnection', () => {
160162

161163
expect(notifyFatalError).toHaveBeenCalledWith(thrownError)
162164
})
165+
166+
it('should log the thrownError', () => {
167+
connection._handleFatalError(thrownError)
168+
169+
expect(loggerFunction).toHaveBeenCalledWith(
170+
'error',
171+
`${connection} experienced a fatal error caused by Neo4jError: some error ` +
172+
'({"code":"C","name":"Neo4jError"})'
173+
)
174+
})
163175
})
164176

165177
describe('when there is current failure on going', () => {
166178
const thrownError = newError('some error', 'C')
167179
const currentFailure = newError('current failure', 'ongoing')
180+
let loggerFunction;
168181
let notifyFatalError;
169182
let connection;
170183

@@ -174,9 +187,10 @@ describe('ChannelConnection', () => {
174187
notifyFatalError,
175188
currentFailure
176189
}
177-
190+
loggerFunction = jest.fn()
191+
const logger = new Logger('info', loggerFunction)
178192
const protocolSupplier = () => protocol
179-
connection = spyOnConnectionChannel({ protocolSupplier })
193+
connection = spyOnConnectionChannel({ protocolSupplier, logger })
180194
})
181195

182196
it('should set connection state to broken', () => {
@@ -196,6 +210,16 @@ describe('ChannelConnection', () => {
196210

197211
expect(notifyFatalError).toHaveBeenCalledWith(currentFailure)
198212
})
213+
214+
it('should log the currentFailure', () => {
215+
connection._handleFatalError(thrownError)
216+
217+
expect(loggerFunction).toHaveBeenCalledWith(
218+
'error',
219+
`${connection} experienced a fatal error caused by Neo4jError: current failure ` +
220+
'({"code":"ongoing","name":"Neo4jError"})'
221+
)
222+
})
199223
})
200224
})
201225

0 commit comments

Comments
 (0)