You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It appears, a range error event is emitted when strict mode is enabled, which can be listened with the on("error") as usual.
However, when this range-error event is emitted, nodejs never emits the on("end") and on("close"). I'm assuming this has something to do with the transform being broken. This doesn't affect the process most of the time, file executes and exits fine but if you need to do cleanup, it could be problematic as it was in my case, where I needed to disconnect the db once the readstream has finished.
Changing the emitted event from error to anything worked and also fired the end and close. Please the sample file and script below to produce the issue. Although I'm not positive if the way it is now is the expected way.
Perhaps something is needed in the transformer to handle this, if not and it's okay, I recommend changing the error to line-error since this is not really a stream related error.
if (!skip && this.options.strict && cells.length !== this.headers.length) {
const e = new RangeError("Row length does not match headers");
this.emit("error", e);
How Do We Reproduce?
head1,head2,head3
a,b,c
x,x,x
e,e
y,y,y
f,f
const csvParser = require("csv-parser");
const fs = require("fs");
const rs = fs.createReadStream("./a.csv");
rs.pipe(
csvParser({
strict: true,
})
)
.on("error", () => {
console.log('caught');
})
.on("end", function () {
console.log("All the data in the file has been read");
})
.on("close", function (err) {
console.log("Stream has been destroyed and file has been closed");
});
The text was updated successfully, but these errors were encountered:
This should be done through the stream transformer, but as a quick fix, you can change the error emit from the module source to something like:
if (!skip && this.options.strict && cells.length !== this.headers.length) {
const e = new RangeError("Row length does not match headers");
e.meta = {
cells: cells,
lineNumber: this.state.lineNumber,
}; /* → injected _meta information */
this.emit("line-error", e);
/* → changed error to line-error so things end, close nicely */
} else {
if (!skip) this.writeRow(cells);
}
and then you can add it to the stream's event handlers with on("line-error", (err) => { console.log('line-error'); }).
Modifying the node_modules is not a good idea, so if you must, I suggest you clone the repository into your project and do changes there, and require from there.
Expected Behavior
Not sure
Actual Behavior
It appears, a
range error
event is emitted when strict mode is enabled, which can be listened with theon("error")
as usual.However, when this
range-error
event is emitted, nodejs never emits theon("end")
andon("close")
. I'm assuming this has something to do with thetransform
being broken. This doesn't affect the process most of the time, file executes and exits fine but if you need to do cleanup, it could be problematic as it was in my case, where I needed to disconnect the db once the readstream has finished.Changing the emitted event from
error
toanything
worked and also fired theend
andclose
. Please the sample file and script below to produce the issue. Although I'm not positive if the way it is now is the expected way.Perhaps something is needed in the
transformer
to handle this, if not and it's okay, I recommend changing theerror
toline-error
since this is not really a stream related error.How Do We Reproduce?
The text was updated successfully, but these errors were encountered: