Open CarlosVilasAlvarez opened 2 years ago
This does not happen in v6 which was just published as a separate package: https://www.npmjs.com/package/@json2csv/node
Although, the API has changed to make the async api more similar than the other.
Also, when piping to an output stream the promise
method has been removed since it's trivial to wait for the end
event and node nowadays even provides the pipeline
method for that.
In v6 you can do:
const { pipeline } = require('node:stream/promises');
// ...
try {
pipeline(asyncParser.parse(mockDataStream), process.stdout).catch(err => {
console.log('Something happened');
});
} catch (error) {
console.log('Hello?');
}
or using the transform
const json2csvTransform = new Transform({ transforms: [dataTransform] }, { objectMode: true });
try {
pipeline(mockDataStream, json2csvTransform, process.stdout).catch(err => {
console.log('Something happened');
});
} catch (error) {
console.log('Hello?');
}
I haven't tested the code. It's just a quick guidelines. If you have more issues with it I can look deeper into it.
Thank you @juanjoDiaz I didn't know that package existed, is this repo "deprecated" then? I think I'll just migrate all the code from v5 to the new v6.
Yup. I'd consider it deprecated. And I think that you'd do well moving to v6 🙂
Hi, I'm having some trouble handling errors caused on data transform functions. json2csv: 5.0.7 Node v16.13.2
When you run this code
You cannot handle the exception, it'll be an unhandledException one.
Only approach that works is to put a try catch inside the data transform function like this.