-
-
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
Would you consider exposing a more structured error type? #108
Comments
Welcome @begleynk! To preface, markdown-rs and the closely related unified js ecosystem, follow a variation on the Unix philosophy:
This module focuses on parsing valid markdown and mdx prioritizing (in order): following the CommonMark and MDX standards, being extensible to support many different use cases, and being fast and efficient. To answer your questions:
|
Thanks for the details! Just to clarify - I agree that putting the rendering logic for the specific kind of error messages I want to show doesn't belong into What I'm really asking about is if you'd be interested in changing the return type for this function (and the Right now the information about where exactly the error came from becomes harder to gather programmatically since it's a Then the user would be able to customize the error presentation, wrapping the library for their own use case, and you could still have the Does that make sense? |
The string is already pretty structured, line, column, reason. What more do you need? I think you should already be able to do what you want with that info. Perhaps it can be a “prettier” result, but what can be done with errors should be the same? The reason I started simple is that this project is no_std + alloc, so it’s very minimal. And errors don’t exist in markdown itself, only in MDX. |
I was hoping that e.g. get the starting position of the offending tag directly for the purpose of creating the custom error I described above. A workaround is using regex to pull them out of the error string. I'm happy to go with that workaround for now if you feel there isn't much use for this outside our admittedly niche use case. We just wanted to customize the error quite heavily so we were hoping to do this without resorting to regex, and figured this may be something others would be interested in. Really impressed with the library. Thank you for creating and maintaining it ❤️ |
<3 Well, you don’t need regex, this whole project doesn’t, should be a relatively small parse ;) What info would you want? Is there more you’d want? Is a small |
Fair point ;) And there's only 6 distinct error messages by my count in
That would be amazing. If possible it would be super useful to also have the end point of the tag being referenced, not just the start. But a brief glance at the code shows that info might not be available where those errors are generated? Also some errors also reference two different tags (i.e. the open and close tag) - it would be great to have positions of both (hence my suggestion for the enum to describe the different cases). But feel free to close this issue, unless you feel there's value in keeping it around. |
There are also errors thrown from the JavaScript parser that is passed in. As that parser is arbitrary, those errors are also arbitrary. markdown-rs/tests/mdx_jsx_flow.rs Line 132 in 60db8e5
I’m open to a PR that uses a simple structure, |
Ah right got it. Thanks for the pointers. The JS parser may make things a bit more complicated I guess if you want to support arbitrary errors - I'll start with parsing the errors myself for now. Happy to report back later how that goes. Thanks again! |
Would you consider exposing a more structured error type that gives users direct access to e.g. the positions of the originating errors? I'm trying to provide some custom error messages to users, but the Mdx errors are all
String
s instead of something more structured.To be more specific, I'd love to be able to give an error along these lines:
In this case, the error string has the starting positions of both the opening and closing tag, but not the length/end point which would be needed to draw the lines under the offending tags.
If the error was instead something along the lines of...
...it would allow for more customization of the errors.
The library could still have
Display
implementations for the error type for convenience and produce errors similar to how it does today.Would you be open/interested in enabling something like this? Happy to take a look at implementing this if you'd like. I might need some pointers on where to start.
The text was updated successfully, but these errors were encountered: