catamphetamine / read-excel-file

Read *.xlsx files in a browser or Node.js. Parse to JSON with a strict schema.
https://catamphetamine.gitlab.io/read-excel-file/
MIT License
301 stars 52 forks source link

FILE ENDED error when trying to parse excel file #86

Open faryalzuberi opened 4 years ago

faryalzuberi commented 4 years ago

I have deployed my code on an Azure App Service container that is running node version v12.16.3. My code works perfectly on my local machine and I am able to parse the same excel file. However on my production environment on Azure I run into this error. The parsing succeeds on every 6th/7th attempt on average.

2020-08-18T08:32:26.341702094Z Error: FILE_ENDED
2020-08-18T08:32:26.342260891Z     at Parse.pull (/node_modules/read-excel-file/node_modules/unzipper/lib/PullStream.js:80:28)
2020-08-18T08:32:26.342421390Z     at Parse.emit (events.js:310:20)
2020-08-18T08:32:26.344061183Z     at Parse.<anonymous> (/node_modules/read-excel-file/node_modules/unzipper/lib/PullStream.js:20:10)
2020-08-18T08:32:26.344410281Z     at Parse.emit (events.js:322:22)
2020-08-18T08:32:26.344805879Z     at finishMaybe (_stream_writable.js:639:14)
2020-08-18T08:32:26.344834579Z     at endWritable (_stream_writable.js:656:3)
2020-08-18T08:32:26.345403076Z     at Parse.Writable.end (_stream_writable.js:595:5)
2020-08-18T08:32:26.345778374Z     at ReadStream.onend (_stream_readable.js:660:10)
2020-08-18T08:32:26.346147072Z     at Object.onceWrapper (events.js:416:28)
2020-08-18T08:32:26.346483171Z     at ReadStream.emit (events.js:322:22)
2020-08-18T08:32:26.346493971Z     at endReadableNT (_stream_readable.js:1187:12)
2020-08-18T08:32:26.346961268Z     at processTicksAndRejections (internal/process/task_queues.js:84:21)

read-excel-file v4.0.7 unzipper version v0.9.15

async function parseFileAsJSONArray(filePath) {
    try {
        return await readXlsxFile(filePath).then((rows) => {
            return rows.map((col) => {
                return col.filter((data) => {
                    return data != null;
                })
            })
        });
    } catch (e) {
        console.log(e);
        return null;
    }

}

router.post('/uploadFile', upload.single("data"), functions.checkRouteSecurity, async (req, res) => {

    if (!req.file) return res.send({ success: false, message: "No file provided" });
    var dataArray = await parseFileAsJSONArray(req.file.path);
    fs.unlink(req.file.path, () => { console.log('deleted file ' + req.file.path) }); // delete file
    if (!(dataArray && dataArray.length > 0)) return res.send({ success: false, message: "Error. Could not parse file" });
    else {
     ...
        res.send(response);
    }
});
remeoj commented 3 years ago

I think this has something to do with using the await function, I'm trying to figure this out now too

alvaroaac commented 3 years ago

I think this has something to do with using the await function, I'm trying to figure this out now too

I have changed my code to use only promises with .then and this error still pops up from time to time. It doesn't happen all the time, which is actually more frustrating as it makes it super hard to debug.

rvpanoz commented 3 years ago

I think this has something to do with using the await function, I'm trying to figure this out now too

I have changed my code to use only promises with .then and this error still pops up from time to time. It doesn't happen all the time, which is actually more frustrating as it makes it super hard to debug.

I am getting the same error, it's true - it doesn't pops up all the time.