Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not emit packet events and stop parsing after a parse error #15

Merged
merged 2 commits into from
Sep 7, 2016

Conversation

jdiamond
Copy link
Contributor

@jdiamond jdiamond commented Sep 5, 2016

For #14.

}

Parser.prototype.parse = function (buf) {
if (this.error) {
this._resetState()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should return early in the if, otherwise it keep resetting itself: if we want to parse two buffer, and the first errors, the second should be ignored. Or maybe errored, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could go either way. _resetState() resets the error as well as the buffer that had the error in it so it shouldn't keep resetting.

If we don't reset the state, calling parse() again with a new buffer is guaranteed to keep emitting the same error over and over since it appends the new buffer after the old.

So we could just tell the user to throw that instance of Parser away, or reset the internal state like I'm doing here. If we do choose not to reset for them, should we at least throw an exception to make it obvious the current instance is broken?

@mcollina
Copy link
Member

mcollina commented Sep 5, 2016

Would you mind updating .travis.yml here as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants