Skip to content

[BUG] this.destroy is not a function #397

@foxmicha

Description

@foxmicha

Describe the bug

When an improperly formatted CSV is passed to the parser, the parser will emit an error. Destroying the stream when this error is received will result in the reference passed to the parser to no longer be defined.

Parsing or Formatting?

  • Formatting
  • Parsing

To Reproduce
Steps to reproduce the behavior:

  1. Example file contents if applicable
    This file contents, with headers on top, can be used to trigger the bug.
"Good", "OK", "BAD", "Empty"
"Good","Good","Good",""
"OK","OK","OK",""
"Bad","Bad","Bad"",""
"Broken","Broken","Broken",""

Line 4 contains the bad data.

  1. Example code to reproduce the issue.
    Some example / pseudo-ish code to reproduce this is below.
var csv = require('fast-csv'),
  fs = require('fs'),
  path = require('path');

var stream = fs.createReadStream(path.resolve("testfile.csv"));

var csvStream = stream.pipe(csv.parse({
     ignoreEmpty: true
}));

csvStream.on("data", function(r) {
    console.log(r);
});

csvStream.on("end", function() {
    console.log("end");
});

csvStream.on("error", function(err) {
    console.log(err);
    stream.destroy;
});

Expected behavior
Stream is not modified by parser. Calling parent is required to destroy stream upon parse failure.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: CentOS
  • OS Version: 7
  • Node Version: 12.16.3

Additional context
Add any other context about the problem here.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions