wavded / ogr2ogr

An ogr2ogr wrapper library
MIT License
216 stars 46 forks source link

Uncaught errors when opening a bad CSV file #86

Closed xqin1 closed 2 years ago

xqin1 commented 2 years ago

When opening a bad CSV file, it creates Uncaught TypeError and crashes the app, and isn't catchable with a try-catch.

 Uncaught TypeError: Cannot read property 'forEach' of undefined
      at /Users/xiaoming/Documents/projects/fcc/FCC-BDC-SDI-Backend/src/node_modules/ogr2ogr/modules/csv.js:44:13
      at /Users/xiaoming/Documents/projects/fcc/FCC-BDC-SDI-Backend/src/node_modules/ogr2ogr/modules/util.js:64:5
      at /Users/xiaoming/Documents/projects/fcc/FCC-BDC-SDI-Backend/src/node_modules/ogr2ogr/modules/csv.js:34:7
      at ReadStream.<anonymous> (node_modules/ogr2ogr/modules/util.js:64:5)
      at ReadStream.<anonymous> (node_modules/ogr2ogr/modules/csv.js:23:10)
      at addChunk (internal/streams/readable.js:309:12)
      at readableAddChunk (internal/streams/readable.js:284:9)
      at ReadStream.Readable.push (internal/streams/readable.js:223:10)
      at internal/fs/streams.js:226:14
      at FSReqCallback.wrapper [as oncomplete] (fs.js:539:5)

Code:

           await ogr2ogr(filePath)
                .format('PostgreSQL')
                .timeout(1200000)
                .options(options)
                .destination(connection)
                .promise();

The process will crash with the uncaught error, instead of catching it in the error event. This is with V2, invalid_ogr_error.csv

wavded commented 2 years ago

It appears you are on an old version of the software, have you tried this with the latest release?

xqin1 commented 2 years ago

The code is on production and it'd be hard to upgrade to the latest version. If the new version fixes the issue, would it be possible to backport to V2? thanks

wavded commented 2 years ago

Unfortunately the new version is a complete rewrite, so backporting would not be possible.

xqin1 commented 2 years ago

I don't see the issue on V3.1. We'll upgrade to the new version. Again, thanks for the excellent work.

close.