petersirka / node-filestorage

Storage for storing uploaded files in node.js
MIT License
72 stars 12 forks source link

SyntaxError: Unexpected end of input #16

Closed oliversalzburg closed 8 years ago

oliversalzburg commented 8 years ago

I'm not quite sure how and why this happened, but I found it in our logs.

undefined:1
{"name":"filename.png","extension":"png","type":"image/png","width":992,"height":638,"length":643583,

SyntaxError: Unexpected end of input
    at Object.parse (native)
    at ReadStream.<anonymous> (/opt/core@5.0.2/node_modules/filestorage/index.js:515:25)
    at ReadStream.g (events.js:260:16)
    at emitOne (events.js:77:13)
    at ReadStream.emit (events.js:169:7)
    at readableAddChunk (_stream_readable.js:146:16)
    at ReadStream.Readable.push (_stream_readable.js:110:10)
    at onread (fs.js:1743:12)
    at FSReqWrap.wrapper [as oncomplete] (fs.js:576:17)

When I try to read the same file again, I can't reproduce the issue. But I also don't know how I could handle this issue if it comes up again.

This was with Node 4.3.1. I'll have now updated to 4.4.2

oliversalzburg commented 8 years ago

From what I understand, you can't rely on receiving all the data in a single data event handler call. It should be buffered before passing the result to JSON.parse.