mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-25 16:03:13 +00:00
fix: Catch and emit query parameter prepareValue(...) errors (#1855)
Adds a try/catch block around the prepareValue(...) invocations in query.prepare(...) to ensure that any that throw an error are caught and bubbled up to the caller.
This commit is contained in:
parent
566058de17
commit
13c14f1de0
@ -194,7 +194,12 @@ Query.prototype.prepare = function (connection) {
|
||||
}
|
||||
|
||||
if (self.values) {
|
||||
self.values = self.values.map(utils.prepareValue)
|
||||
try {
|
||||
self.values = self.values.map(utils.prepareValue)
|
||||
} catch (err) {
|
||||
this.handleError(err, connection)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// http://developer.postgresql.org/pgdocs/postgres/protocol-flow.html#PROTOCOL-FLOW-EXT-QUERY
|
||||
|
||||
33
test/integration/gh-issues/1854-tests.js
Normal file
33
test/integration/gh-issues/1854-tests.js
Normal file
@ -0,0 +1,33 @@
|
||||
"use strict"
|
||||
var helper = require('./../test-helper')
|
||||
|
||||
const suite = new helper.Suite()
|
||||
|
||||
suite.test('Parameter serialization errors should not cause query to hang', (done) => {
|
||||
if (helper.config.native) {
|
||||
// pg-native cannot handle non-string parameters so skip this entirely
|
||||
return done()
|
||||
}
|
||||
const client = new helper.pg.Client()
|
||||
const expectedErr = new Error('Serialization error')
|
||||
client.connect()
|
||||
.then(() => {
|
||||
const obj = {
|
||||
toPostgres: function () {
|
||||
throw expectedErr
|
||||
}
|
||||
}
|
||||
return client.query('SELECT $1::text', [obj])
|
||||
.then(() => {
|
||||
throw new Error('Expected a serialization error to be thrown but no error was thrown')
|
||||
})
|
||||
})
|
||||
.catch((err) => {
|
||||
client.end(() => {})
|
||||
if (err !== expectedErr) {
|
||||
done(new Error('Expected a serialization error to be thrown but instead caught: ' + err))
|
||||
return
|
||||
}
|
||||
done()
|
||||
})
|
||||
})
|
||||
Loading…
x
Reference in New Issue
Block a user