Skip to content
This repository was archived by the owner on Dec 4, 2018. It is now read-only.

Fix for ticket #112 - incomplete json#117

Open
robaca wants to merge 10 commits into
dominictarr:masterfrom
codecentric:master
Open

Fix for ticket #112 - incomplete json#117
robaca wants to merge 10 commits into
dominictarr:masterfrom
codecentric:master

Conversation

@robaca

@robaca robaca commented Dec 22, 2016

Copy link
Copy Markdown

No description provided.

@dominictarr

Copy link
Copy Markdown
Owner

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

@robaca

robaca commented Dec 22, 2016

Copy link
Copy Markdown
Author

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

robaca commented Dec 22, 2016

Copy link
Copy Markdown
Author

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

@dominictarr

Copy link
Copy Markdown
Owner

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

robaca commented Apr 20, 2017

Copy link
Copy Markdown
Author

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

@dominictarr

Copy link
Copy Markdown
Owner

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

@robaca

robaca commented Apr 21, 2017

Copy link
Copy Markdown
Author

@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

robaca commented Apr 21, 2017

Copy link
Copy Markdown
Author

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

@lojzatran

Copy link
Copy Markdown

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

robaca commented Jul 13, 2017

Copy link
Copy Markdown
Author

Any updates on this? Tests are passing according to Travis

@lojzatran

Copy link
Copy Markdown

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

@robaca

robaca commented Jul 13, 2017

Copy link
Copy Markdown
Author

npm run test =>

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

Tested on Node 4/6/8

@robaca

robaca commented Jul 13, 2017

Copy link
Copy Markdown
Author

Ok, now I understood ;-)

@robaca

robaca commented Jul 14, 2017

Copy link
Copy Markdown
Author

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

@robaca

robaca commented Aug 11, 2017

Copy link
Copy Markdown
Author

@dominictarr do you need anything more for the merge?

@ruettenm

Copy link
Copy Markdown

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

@junajan

junajan commented Oct 30, 2017

Copy link
Copy Markdown

+1 :)

@vancouverwill

vancouverwill commented Jun 1, 2018

Copy link
Copy Markdown

this would be really helpful guys! :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants