Fix JSON.parsing when streaming changes #11

Closed
wants to merge 2 commits into
from

Projects

None yet

2 participants

@mugami-ast

When streaming a lot of changes, a chunk might only be a partial JSON string, which results in the current code throwing a syntax error.

Refactor proto._stream()

commit 4fe5060

The goal of this patch is to remove noise from the next patch.

Reasoning:
- JSON.parse takes a string as input, therefore clearly reject
  non-strings.
- Since we now know that chunk is a string, directly check the length.

lib/client.js |   22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)

Handle JSON errors in proto._stream()

commit c901c23

In order To handle partial JSON chunks, use a buffer, and only emit a
parse error if the buffer remains unparsable for the whole period
defined by the new error_timeout option (default: 500ms).

lib/client.js |   22 +++++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
mugami-ast added some commits Jun 8, 2012
@mugami-ast mugami-ast Refactor proto._stream()
The goal of this patch is to remove noise from the next patch.

Reasoning:
- JSON.parse takes a string as input, therefore clearly reject
  non-strings.
- Since we now know that chunk is a string, directly check the length.

Signed-off-by: Asbjørn Sloth Tønnesen <ast@veridu.com>
4fe5060
@mugami-ast mugami-ast Handle JSON errors in proto._stream()
In order To handle partial JSON chunks, use a buffer, and only emit a
parse error if the buffer remains unparsable for the whole period
defined by the new error_timeout option (default: 500ms).

Signed-off-by: Asbjørn Sloth Tønnesen <ast@veridu.com>
c901c23
@dominicbarnes

Ok, I manually merged in your code with this commit 7dd7666. Not sure how I got my commit history all messed up, but v1.2.2 should fix this. Let me know if it does not.

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