Skip to content

Commit bd04758

Browse files
committed
Merge pull request brianc#242 from CartoDB/master-error-on-missing-stream
Cleanly handle missing stream error on COPY operation. Closes brianc#241
2 parents d55cae5 + 2fc22de commit bd04758

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/connection.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ p.sendCopyFromChunk = function (chunk) {
267267
p.endCopyFrom = function () {
268268
this.stream.write(this.writer.add(emptyBuffer).flush(0x63));
269269
}
270+
p.sendCopyFail = function (msg) {
271+
//this.stream.write(this.writer.add(emptyBuffer).flush(0x66));
272+
this.writer.addCString(msg);
273+
this._send(0x66);
274+
}
270275
//parsing methods
271276
p.setBuffer = function(buffer) {
272277
if(this.lastBuffer) { //we have unfinished biznaz

lib/query.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ var Query = function(config, values, callback) {
1717
this.types = config.types;
1818
this.name = config.name;
1919
this.binary = config.binary;
20-
this.stream = config.stream;
20+
this.stream = config.stream;
2121
//use unique portal name each time
2222
this.portal = config.portal || ""
2323
this.callback = config.callback;
@@ -170,9 +170,14 @@ p.prepare = function(connection) {
170170
this.getRows(connection);
171171
};
172172
p.streamData = function (connection) {
173-
this.stream.startStreamingToConnection(connection);
173+
if ( this.stream ) this.stream.startStreamingToConnection(connection);
174+
else connection.sendCopyFail('No source stream defined');
174175
};
175176
p.handleCopyFromChunk = function (chunk) {
176-
this.stream.handleChunk(chunk);
177+
if ( this.stream ) this.stream.handleChunk(chunk);
178+
else {
179+
// TODO: signal the problem somehow
180+
//this.handleError(new Error('error', 'No destination stream defined'));
181+
}
177182
}
178183
module.exports = Query;

0 commit comments

Comments
 (0)