Stop parsing #58

jechenique opened this Issue Nov 3, 2012 · 2 comments

2 participants


is there any way to stop the file process in case that an error ocurrs?
I've been trying to do it with the end method but it doesn't works.
I've posted a question here about it:



Thanks for your report, I'll look at it in the next few days


In its latest version (0.2.2), the parser use a pipe implementation when you call csv() However, and you can check it by yourself in the Node.js source code, the pipe function doesn't call the source destroy function when an error occured in the destination. It is your responsibility. I check on my own with a large source file, and it work with this example:

source = __dirname+'/test.csv';
source = fs.createReadStream(source);
source.on('end', function(){ console.log('source end') })
source.on('error', function(){ console.log('source error') })
source.on('close', function(){ console.log('source close') })

  .on('record', function(data, index){
    var date = data[0];
    var vehicle = data[1];
    error = date + ' | ' + vechile;
  .on('end', function() {
    console.log('csv end');
  .on('error', function(error) {
    console.log('csv error');

Yes, error is called multiple times because destroy is an async operation but the source stream is closed before it reach the end of the file.

At this point, it is your responsibility to implement the logic where the code handling the error is only called once. However, we could add an option to the parser like "stopOnError" to prevent the error listener to be called more than once. In such case, if you find it interesting, then please open a new issue (and please suggest me a better name: ).


@wdavidw wdavidw closed this Nov 5, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment