mafintosh / csv-parser

Streaming csv parser inspired by binary-csv that aims to be faster than everyone else
MIT License
1.41k stars 134 forks source link

Doesn't work within Docker, while correctly runs on Local #189

Closed Jigar3 closed 3 years ago

Jigar3 commented 3 years ago

Expected Behavior

Running on Docker should return the same result.

Actual Behavior

While running on Docker, the promise Rejects, instead of resolving with the correct values. It works fine on the local machine I am running on.

How Do We Reproduce?

import csv from 'csv-parser';
import { Readable } from 'stream';

const parseCSVToJSON = (csvString: string) => {
    return new Promise((resolve, reject) => {
        logger.info(csvString);
        const results: Array<any> = [];
        Readable.from([csvString])
            .pipe(csv())
            .on('data', (data) => results.push(data))
            .on('end', () => {
                logger.info(results);
                if (results.length == 0) { reject([]); }
                else { resolve(results); }
            });
    });
};

This is the function I am using and calling it like below

const parsedData = await parseCSVToJSON(keyDrivers.toString()).catch(err => {
        return res.json({ args: req.body, data: '', err: err });
    });

return res.json({ args: req.body, data: parsedData });

So, on my local machine, I correctly get the response, but on Docker, I get the response of the catch block.

Any ideas why this might be happening? Any help appreciated.

Jigar3 commented 3 years ago

I was able to fix this by using the same Node version on Docker, but still would like to know why was it not working v12.2.0

TrySound commented 3 years ago

Hi. With what promise rejects? 12.2 is very old version and may contain bugs. Better upgrade to the latest lts.

Jigar3 commented 3 years ago

The promise rejects with empty object

TrySound commented 3 years ago

I would use get-stream to convert stream to promise. Streams are tricky to handle properly.

Jigar3 commented 3 years ago

Cool, thanks. You can close this issue.