From 9d090bc1bf170cbbf2dc15de3354351ed4f035c7 Mon Sep 17 00:00:00 2001 From: Paul Collier Date: Mon, 1 Nov 2010 18:06:44 -0700 Subject: [PATCH] Propagate errors during queries to the Query --- lib/client.js | 6 ++++++ test/integration/client/error-handling-tests.js | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/client.js b/lib/client.js index 378134a9d..0e0f3717c 100644 --- a/lib/client.js +++ b/lib/client.js @@ -128,12 +128,18 @@ p.submit = function(connection) { var handleDatarow = function(msg) { self.onDataRow(msg); }; + var handleError = function(msg) { + self.emit('error', msg); + connection.sync(); + }; connection.on('rowDescription', handleRowDescription); connection.on('dataRow', handleDatarow); + connection.on('error', handleError); connection.once('readyForQuery', function() { //remove all listeners connection.removeListener('rowDescription', handleRowDescription); connection.removeListener('dataRow', handleDatarow); + connection.removeListener('error', handleError); self.emit('end'); }); }; diff --git a/test/integration/client/error-handling-tests.js b/test/integration/client/error-handling-tests.js index b9e93b8b0..43ca150be 100644 --- a/test/integration/client/error-handling-tests.js +++ b/test/integration/client/error-handling-tests.js @@ -2,8 +2,8 @@ var helper = require(__dirname + '/test-helper'); test('error handling', function(){ var client = helper.client(); - client.query("select omfg from yodas_soda where pixistix = 'zoiks!!!'"); - assert.emits(client, 'error', function(error) { + var query = client.query("select omfg from yodas_soda where pixistix = 'zoiks!!!'"); + assert.emits(query, 'error', function(error) { assert.equal(error.severity, "ERROR"); client.end(); });