Skip to content

Improve error logging during fatal failures in the Connection #812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 10, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export default class ChannelConnection extends Connection {

if (this._log.isErrorEnabled()) {
this._log.error(
`experienced a fatal error ${json.stringify(this._error)}`
`experienced a fatal error caused by ${this._error} (${json.stringify(this._error)})`
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ describe('ChannelConnection', () => {
describe('._handleFatalError()', () => {
describe('when there is not current failure on going', () => {
const thrownError = newError('some error', 'C')
let loggerFunction;
let notifyFatalError;
let connection;

Expand All @@ -138,9 +139,10 @@ describe('ChannelConnection', () => {
notifyFatalError,
currentFailure: null
}

loggerFunction = jest.fn()
const logger = new Logger('info', loggerFunction)
const protocolSupplier = () => protocol
connection = spyOnConnectionChannel({ protocolSupplier })
connection = spyOnConnectionChannel({ protocolSupplier, logger })
})

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

expect(notifyFatalError).toHaveBeenCalledWith(thrownError)
})

it('should log the thrownError', () => {
connection._handleFatalError(thrownError)

expect(loggerFunction).toHaveBeenCalledWith(
'error',
`${connection} experienced a fatal error caused by Neo4jError: some error ` +
'({"code":"C","name":"Neo4jError"})'
)
})
})

describe('when there is current failure on going', () => {
const thrownError = newError('some error', 'C')
const currentFailure = newError('current failure', 'ongoing')
let loggerFunction;
let notifyFatalError;
let connection;

Expand All @@ -174,9 +187,10 @@ describe('ChannelConnection', () => {
notifyFatalError,
currentFailure
}

loggerFunction = jest.fn()
const logger = new Logger('info', loggerFunction)
const protocolSupplier = () => protocol
connection = spyOnConnectionChannel({ protocolSupplier })
connection = spyOnConnectionChannel({ protocolSupplier, logger })
})

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

expect(notifyFatalError).toHaveBeenCalledWith(currentFailure)
})

it('should log the currentFailure', () => {
connection._handleFatalError(thrownError)

expect(loggerFunction).toHaveBeenCalledWith(
'error',
`${connection} experienced a fatal error caused by Neo4jError: current failure ` +
'({"code":"ongoing","name":"Neo4jError"})'
)
})
})
})

Expand Down