-
Notifications
You must be signed in to change notification settings - Fork 16
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
Include additional structured information in error objects #26
Comments
Thanks for the suggestion! For the sake of discussion, here's an accurate example of the current structure of a parse-xml error object: {
message: 'Unclosed start tag for element `unclosed` (line 1, column 15)\n' +
' <xml><unclosed</xml>\n' +
' ^\n',
column: 15,
excerpt: '<xml><unclosed</xml>',
line: 1,
pos: 14
} parse-xml errors don't have numeric codes associated with them, so there wouldn't be anything to include in an It sounds like the main things you're looking for are a short, generic version of the message without formatting (like "Unclosed start tag for element") and an One difficulty is that not all error messages are associated with elements. Some are associated with attributes, entities, characters, comments, etc. Others aren't associated with any specific part of the document because they occur when the input is invalid. It may be difficult to represent all possible cases in a useful way. It might help to understand how you're hoping to represent these errors in a UI. |
It looks like you should be able to achieve that UI using the existing error objects by stripping off the end of the let strippedMessage = error.message.replace(/\s+\(line [\s\S]+/, '');
// => 'Unclosed start tag for element `unclosed`' This should work with all parse-xml errors, since they all follow the same format. While I agree that adding error codes could make it easier for consumers to identify error types, one hesitation I have about this is that there are actually quite a few possible error types (more than 30). Exporting constants for 30+ error codes would increase the size of the library, and I suspect most people wouldn't use them. I'll give it some thought though. |
That works for me, thanks! |
Awesome! I'll go ahead and close this since it sounds like there's nothing more to do here. 😄 |
Reopening since there's been a second request for error codes, so it sounds like that may be worth looking into. |
I am particularly interested in a HTML has slowly started defining their “parse errors” (even though HTML does not have actual errors). Here’s a short list of examples: https://github.com/syntax-tree/hast-util-from-html#optionskey-in-errorcode. Might be useful as inspiration? |
Thanks for this library, its the only one I've found with useful, descriptive error handling besides the DOMParser.
Would it be possible to extend the error object to break down the message a bit more? What I have in mind is to go from this:
To this:
I know some of those entries are already in the object, which is great. Having the extra ones, like
errorCode
,message
andelement
or similar would help with UI work.The text was updated successfully, but these errors were encountered: