Improved custom error tutorial / how-to? #537
Replies: 2 comments 6 replies
-
To provide direction improving this, it would help to know what question you had or challenge that led you to custom errors and how the documentation didn't help. |
Beta Was this translation helpful? Give feedback.
-
Sure! So, I'm having issues because I'm in a bit of a weird edge case here. I'm trying to parse vb6 code, so of course, I can't use UTF since it predates it and we get all kinds of weird broken characters. This means I have to use &'a [u8] or BStr (from burntsushi, another awesome crate as well!) This means I need to implement things carefully to get it to work with this non-standard stream. I get a ton of 'as Stream' trait restrictions which I need to handle. That I eventually figured out since you have a whole section on implementing Stream, but we don't have a similar basic walkthrough for errors. I'm generally looking for 'how to implement custom errors' as a walkthrough. The one we have is...very barebones and when I tried to do the same thing for another section of my code, and I think I've done it the same way, it utterly failed and fell down. I'm definitely doing something wrong, but I can't figure out what since I'm getting lost in the traits. The Stream section was very clear: implement these traits, use them in this way, result! The example is barebones, but it definitely gets things across. It's not so much 'the info isn't here' I'm sure it is. I'm just having issue converting 'reference material' into 'functional understanding.' You can check out what I've got so far at: https://github.com/scriptandcompile/vb6parse/tree/master/src and you can see in the project.rs and error.rs that I've got....some.... idea how this is supposed to work, but I'm definitely not using the library in the right way. I started to work on classes.rs (the first place where we have actual AST parsing that will need to happen!) I've mostly cobbled things together in a working-ish way, but I'm having a lot of issue so it's clear I'm doing something wrong with this and it feels like I'm trying to operate a chainsaw with my feet. It's very clearly not the chainsaw's fault, I'm doing something wrong here, but all I've got is a maintenance and assembly guide to the chainsaw so I'm doing the best I can! But, I'm not sure where and how and why things are going sideways. Lots of 'type annotation needed <_, ParseError> stuff popping up and it just feels...like I'm fighting things instead of doing things the 'right way' (tm). |
Beta Was this translation helpful? Give feedback.
-
First off, thanks for the hard work making an awesome library!
Is there anywhere we can get more information on how to do custom errors with winnow?
The tutorial mentions error reporting then goes into a tangent around err_cut and nothing really more is found. There is some discussion in: https://docs.rs/winnow/latest/winnow/_topic/error/index.html but I'm not sure how out of date this is since it mentions nom.
Ideally, more depth could be had around how custom errors fit into the entire ecosystem.
How a custom error can be reported with the context around it (with an example!) how that fits into ErrorContext, ErrorTree, ErrKind, ErrMode, ParserError, AddContext, and FromExternalError.
When it comes to the docs (and theory of documentation https://docs.divio.com/documentation-system/) you have reference nailed. Tutorial is...alright, explanation is adequate enough, and how-to is almost non-existent.
Do you have a suggestion for further reading/tutorials/how-to's/videos? I've basically found two videos on youtube (https://www.youtube.com/watch?v=QF3kMyzMC40 and https://www.youtube.com/watch?v=LUcI6KkM-PE) but these are more a rough look around of what winnow is and a bit of 'getting to know the general area' type thing.
Beta Was this translation helpful? Give feedback.
All reactions