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

Consumer::run doesn't stop after ConsumerState::ConsumerError is returned #52

Closed
daboross opened this issue Jun 13, 2015 · 2 comments
Closed

Comments

@daboross
Copy link
Contributor

If you return ConsumerError from Consumer::consume, Consumer::run will essentially run in an infinite loop. I think this is due to the empty match branch in https://github.com/Geal/nom/blob/master/src/consumer.rs#L162.

Consumer::run() should ideally stop execution (at least stop calling Consumer::consume with invalid data) when this happens. With the current behavior, it's impossible to recover from parsing invalid data using a Consumer.

@Geal
Copy link
Collaborator

Geal commented Jun 15, 2015

Good catch! I added a failed method to the consumer trait that will be called (and end the loop) if the parsing failed: 35a7bfa

Would that be ok for your needs? I have to admit that I am less fond of the consumer system now, there may be a better way to encode a state machine. I'll let you know if I advance on this.

@daboross
Copy link
Contributor Author

Yeah, that seems to work nicely! I think it might be a bit nicer to directly return a Result<> from the run method, but this way of doing things works 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

No branches or pull requests

2 participants