From de9d5e3cd5466bda6554fd631c51196c78b80816 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 16 Jan 2013 10:11:55 +0100 Subject: [PATCH] Cleanly handle missing stream error on COPY operation. Closes #241 --- lib/query.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/query.js b/lib/query.js index a3330231..1185a2ad 100644 --- a/lib/query.js +++ b/lib/query.js @@ -170,9 +170,11 @@ p.prepare = function(connection) { this.getRows(connection); }; p.streamData = function (connection) { - this.stream.startStreamingToConnection(connection); + if ( this.stream ) this.stream.startStreamingToConnection(connection); + else this.handleError(new Error('No destination stream defined')); }; p.handleCopyFromChunk = function (chunk) { - this.stream.handleChunk(chunk); + if ( this.stream ) this.stream.handleChunk(chunk); + else this.handleError(new Error('error', 'No source stream defined')); } module.exports = Query;