Skip to content
Closed
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
1 change: 1 addition & 0 deletions packages/pg-pool/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function makeIdleListener(pool, client) {
class Pool extends EventEmitter {
constructor(options, Client) {
super()
this.on('error', NOOP)
this.options = Object.assign({}, options)

if (options != null && 'password' in options) {
Expand Down
5 changes: 5 additions & 0 deletions packages/pg-pool/test/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ const it = require('mocha').it
const Pool = require('../')

describe('events', function () {
it('does not throw when an error has no listener', function () {
const pool = new Pool()
expect(() => pool.emit('error', new Error('problem'))).not.to.throwError()
})

it('emits connect before callback', function (done) {
const pool = new Pool()
let emittedClient = false
Expand Down
1 change: 1 addition & 0 deletions packages/pg/lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ function coerceNumberOrDefault(value, defaultValue) {
class Client extends EventEmitter {
constructor(config) {
super()
this.on('error', () => {})

this.connectionParameters = new ConnectionParameters(config)
this.user = this.connectionParameters.user
Expand Down
1 change: 1 addition & 0 deletions packages/pg/lib/native/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const queryQueueLengthDeprecationNotice = nodeUtils.deprecate(

const Client = (module.exports = function (config) {
EventEmitter.call(this)
this.on('error', () => {})
config = config || {}

this._Promise = config.Promise || global.Promise
Expand Down
7 changes: 7 additions & 0 deletions packages/pg/test/unit/client/configuration-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ test('client settings', function () {
})
})

test('emitting an error without a listener does not throw', function () {
const client = new Client()
assert.doesNotThrow(function () {
client.emit('error', new Error('expected'))
})
})

test('initializing from a config string', function () {
test('uses connectionString property', function () {
const client = new Client({
Expand Down
Loading