dominictarr / JSONStream

rawStream.pipe(JSONStream.parse()).pipe(streamOfObjects)
Other
1.92k stars 165 forks source link

Fix for ticket #112 - incomplete json #117

Open robaca opened 7 years ago

dominictarr commented 7 years ago

that looks right, but I think it should return after emitting the error.

robaca commented 7 years ago

as we still need the end event, we still have to execute stream.queue afterwards. I moved the error handling so that existing headers/footers may be emitted before the error

robaca commented 7 years ago

the test all pass on my machine, with node versions 4 and 6

dominictarr commented 7 years ago

ah, node streams do not have an end event after an error. an error event unpipes the stream https://github.com/nodejs/node/blob/master/lib/_stream_readable.js#L574-L580

fs Readable stream also does not make an end event after an error https://github.com/nodejs/node/blob/master/lib/fs.js#L1821-L1836

robaca commented 7 years ago

@dominictarr I fixed the code and existing tests that assumed that end was still emitted after error. This may not be backwards compatible.

dominictarr commented 7 years ago

@cmjartan can you describe what it may be incompatible with? if it sounds slightly serious, I'll make it a new major version.

robaca commented 7 years ago

@dominictarr checked my changes again, and I think it's not incompatible. It's just that some tests like destroy_missing were non-functional before, and that irritated me.

robaca commented 7 years ago

it's not always clear for me by reading the tests which scenario is meant to be tested

lojzatran commented 7 years ago

Hi @cmjartan I tried your PR and this test case fails:

test('#112 "Incomplete JSON" error is emitted', function (t) {
   var stream = JSONStream
    .parse()
    .on('error', function (err) {
        t.ok("error emitted: " + err.message)
        t.end()
    })

    stream.write('{"rows":[{"id":"id-1","name":"Name A"}') // I changed the incomplete JSON
    stream.end()
})
robaca commented 7 years ago

Any updates on this? Tests are passing according to Travis

lojzatran commented 7 years ago

@cmjartan did you try to run my test in the comment? It does not pass.

robaca commented 7 years ago

npm run test =>

# #112 "Incomplete JSON" error is emitted
ok 6 (unnamed assert)

Tested on Node 4/6/8

robaca commented 7 years ago

Ok, now I understood ;-)

robaca commented 7 years ago

@dominictarr now it should be more reliable. I also check if the stack is empty at the end.

robaca commented 7 years ago

@dominictarr do you need anything more for the merge?

ruettenm commented 7 years ago

@dominictarr it would be nice to see this PR on master :-)

junajan commented 7 years ago

+1 :)

vancouverwill commented 6 years ago

this would be really helpful guys! :)