-
Notifications
You must be signed in to change notification settings - Fork 53
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
Role of ErrorKind
and intent of the variants?
#697
Comments
One idea is to remove them completely. The other is to shift the focus to describing the failure and to focus on the core principles of why something fails: enum ErrorKind {
// For `fail`
Failed,
// Use for `one_of`, `take_while`/`repeat` ending early besides eof, `verify`, `try_map`
Invalid,
// Used for operations that hit `eof` when data was expected, including `complete_err`
EofFound,
// Parser pre-condition was not met
Assert,
} |
That's a pretty good question. In my mind, it kind of depends on how a user wants to use the library. One scenario where an ErrorKind might be useful would be when one is trying to implement some kind of error recovery strategy. Personally, I don't really need the ErrorKind yet. I simply had to create a backtrack error by hand, which required any ErrorKind. I decided to just use the FYI, I'm currently writing parsers for hand-crafted and very poorly structured file formats in the scope of Arch Linux package management. (Over here in case you're interested :D) My usecase is that those file formats have no "nice" indicators/syntax on when a certain section is finished, which requires me to peek ahead and throw a backtracking error if I find a new section so that I can escape the current |
To be honest, error handling in winnow is one of the last things that haven't really clicked for me yet. I'll probably spend a few hours soon to add good error handling to those libraries, maybe I'll finally understand how to do proper error handling with winnow 😅 |
Wouldn't |
Good point. I forgot about that! |
Ok. I think I got a pretty good grasp on how to do proper backtracking and error handling now. In general, I really don't see the need for the current I took some time and tought about error recovery specifically and how this would look in winnow on a library level. I guess to have something like error recovery, it would need to be properly baked into winnow. For this to be ergonomic, there would need to be some form of error aggregation mechanic and a dedicated "We found an error, seek to this position and continue with the Considering that this would likely require a significant restructurization of IMO error recovery would be a really nice touch, but this is a different topic :) |
We are tracking error recovery in #96 which has an unstable implementation that includes
|
Haha, perfect. Let's kick ErrorKind out then :) |
I think the Errors are the most confusing thing about nom/winnow. Some issues I have with it is: Also, looking at the parser example in https://docs.rs/winnow/latest/winnow/_topic/partial/index.html And I'm sure there are ways to handle my issues, since I'm quite new at winnow, but the rest of the framework feels quite intuitive so the Errors feels very like a mess. So, I'm happy to see that you are looking into this area, and I hope you find a way to simplify it. And maybe just some better documentation explaining how the Error handling is meant to work. |
@snaggen thank you for sharing your experience! Understanding how people are approaching Winnow and dealing with problems is a big help in figuring out how to improve it. Could you start a Discussion on that topic? It looks different enough from this issue and there are enough points to cover, that having a dedicated, threaded conversation would help in finding how to help solve those problems. |
Some early expectations of
ErrorKind
fromnom
&[ErrorKind]
, inspired by another parser library (can't find where I saw this written)Today in Winnow, none of these apply and the default error type drops
ErrorKind
. It is hard to infer intent fromErrorKind
because which one is reported is an implementation detail in a lot of circumstances.Also,
ErrorKind
variants are focused on what operation failed, instead of describing the failureErrorKind::Eof
when an eof is found but its for when an eof isn't found)AddContext
can serve a similar role, though isn't applied to built-in parsersWhere should
ErrorKind
go?The text was updated successfully, but these errors were encountered: