Skip to content

Commit

Permalink
Correctly emit errors thrown when we attempt to parse a line.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex J Burke committed Feb 7, 2014
1 parent 821ef45 commit 8f5091f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/ya-csv.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var csv = exports;
*/
var CsvReader = csv.CsvReader = function(readStream, options) {
var self = this;
var hasEnded = false;
_setOptions(self, options);

self.parsingStatus = {
Expand All @@ -42,7 +43,18 @@ var CsvReader = csv.CsvReader = function(readStream, options) {
};

if (readStream) {
readStream.addListener('data', this.parse.bind(this));
readStream.addListener('data', function (data) {
if (hasEnded) {
return;
}

try {
self.parse(data);
} catch (e) {
hasEnded = true;
self.emit('error', e);
}
});
readStream.addListener('error', this.emit.bind(this, 'error'));
readStream.addListener('end', this.end.bind(this));

Expand Down

0 comments on commit 8f5091f

Please sign in to comment.