Skip to content

Commit bd74d48

Browse files
committed
Fix query error emit on native bindings
1 parent 6d64abc commit bd74d48

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/native/query.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ var NativeQuery = function(config, values, callback) {
2727

2828
this._result = new Result(config.rowMode);
2929
this._addedFields = false;
30+
this._hadError = false;
3031
//normalize values
3132
if(this.values) {
3233
for(var i = 0, len = this.values.length; i < len; i++) {
@@ -55,6 +56,7 @@ NativeQuery.prototype.handleError = function(error) {
5556
error = this._canceledDueToError;
5657
this._canceledDueToError = false;
5758
}
59+
this._hadError = true;
5860
if(this.callback) {
5961
var cb = this.callback;
6062
//remove callback to prevent double call on readyForQuery
@@ -66,6 +68,7 @@ NativeQuery.prototype.handleError = function(error) {
6668
};
6769

6870
NativeQuery.prototype.handleReadyForQuery = function(meta) {
71+
if(this._hadError) return;
6972
if (this._canceledDueToError) {
7073
return this.handleError(this._canceledDueToError);
7174
}

test/integration/client/query-error-handling-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test('error during query execution', function() {
2020
//because it was killed and received an error
2121
//https://github.com/brianc/node-postgres/issues/547
2222
query1.on('end', function() {
23-
assert.fail('Client with an error should not emit "end" event')
23+
assert.fail('Query with an error should not emit "end" event')
2424
})
2525
var client2 = new Client(helper.args);
2626
client2.connect(assert.success(function() {

0 commit comments

Comments
 (0)