antelle / node-stream-zip

node.js library for fast reading of large ZIPs
Other
447 stars 63 forks source link

node-stream-zip crashes when a bad file is opened #71

Closed vnaganathan-conga closed 3 years ago

vnaganathan-conga commented 3 years ago

In general, most errors seem uncaught causing the node engine to crash. This issue is unfortunately not workaroundable. It makes us rethink about the use of node-stream-zip

{ Error [ERR_UNHANDLED_ERROR]: Unhandled error. ('Bad archive') at StreamZip.emit (events.js:187:17) at StreamZip.emit (.../node_modules/node-stream-zip/node_stream_zip.js:607:33) at FsRead.readUntilFoundCallback [as callback] (..../node_modules/node-stream-zip/node_stream_zip.js:210:25) at FsRead.readCallback (..../node_modules/node-stream-zip/node_stream_zip.js:878:21) at FSReqWrap.wrapper [as oncomplete] (fs.js:467:17) context: 'Bad archive' } Waiting for the debugger to disconnect...

antelle commented 3 years ago

Hi! Could you please paste how you use the library? I see that errors work well in tests.

antelle commented 3 years ago

I think you're not listening to error event, that's why it happens. If you add something like

zip.on('error', (err) => { logger.error(err) });

it should disappear.

vnaganathan-conga commented 3 years ago

Thanks @antelle, i will try your suggestion. Appreciate your quick response

antelle commented 3 years ago

Now there's also async API available, it's a bit easier to use and may worth trying, then you would get error handling automatically if you pur your async call in try..catch.