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

Throw stream errors #323

Open
ark0f opened this issue Aug 12, 2021 · 5 comments
Open

Throw stream errors #323

ark0f opened this issue Aug 12, 2021 · 5 comments

Comments

@ark0f
Copy link
Contributor

ark0f commented Aug 12, 2021

I have stream of tokens. Token is enum like:

enum Token {
    Error,
    Num,
    Str,
    ...
}

StreamOnce::uncons documentation: Returns Err if no element could be retrieved.
How I can throw error when I have Token::Error?

@Marwes
Copy link
Owner

Marwes commented Aug 14, 2021

You would return an error if the stream can no longer be used to retrieve more tokens. If you have a specific error token the I would assume that the stream may still be used, just that one token was an error so you would return Ok(Token::Error) to allow the parsing to continue (if the parser accepts, and recovers from the error token that is)

@ark0f
Copy link
Contributor Author

ark0f commented Aug 14, 2021

I would assume that the stream may still be used

Not always. Unfinished string can break all following lexing

if the parser accepts, and recovers from the error token that is

That the only solution I found. I created my own token parser, but is it idiomatic way to handle such errors in combine?

@Marwes
Copy link
Owner

Marwes commented Aug 23, 2021

That the only solution I found. I created my own token parser, but is it idiomatic way to handle such errors in combine?

Yes, I think so at least. What would be the alternative?

@ark0f
Copy link
Contributor Author

ark0f commented Aug 23, 2021

What would be the alternative?

Throw error from stream (maybe). It gives more guarentees that invalid input won't be skipped.

Otherwise I have to be sure that every parsing action is based on my own token parser

@Marwes
Copy link
Owner

Marwes commented Aug 23, 2021

I suppose you could instead use a parser which inspects the error being returned and recovers if you deem it to be a recoverable error

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