Comments (7)
That works for me, thanks!
from parse-xml.
Reopening since there's been a second request for error codes, so it sounds like that may be worth looking into.
from parse-xml.
I am particularly interested in a code
for errors, so their kind can be categorised some way even though their text is a bit different.
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?
from parse-xml.
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 errorCode
property. What you've labeled "snippet" is available via the excerpt
property, and "col" is available as column
.
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 element
property containing the name of the unclosed element. Is that correct?
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.
from parse-xml.
Thanks for the reply!
Here's the UI I'd ideally like to make using the error you gave as an example.
A short, generic message + element property would be great. That way I can present the error to users and forward them to the line/col in my editor interface when they click the [...] button in the error.
If there were unique data-structures associated with error objects, having error codes would offer an easy way to case/switch between error message components on a frontend, as opposed to checking if properties exist.
from parse-xml.
It looks like you should be able to achieve that UI using the existing error objects by stripping off the end of the message
string, starting with the line and column numbers. Here's a regex that would do it:
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.
from parse-xml.
Awesome! I'll go ahead and close this since it sounds like there's nothing more to do here. 😄
from parse-xml.
Related Issues (18)
- Consider adding opt-in support for parsing XML 1.1 HOT 3
- RegExp issue with very long attributes HOT 1
- Does it support running in WebWorkers? HOT 2
- Very cool lib HOT 1
- Question "claims to test an illegal char, but tests the wrong char" HOT 3
- xml.replace is not a function HOT 1
- Serialising back to XML
- Documentation says second argument is optional, but TS compiler says its required HOT 3
- Positional info HOT 6
- Add type information for errors
- Don't trim comment content
- Text content following CDATA is appended to a preceding `XmlCdata` node
- Option to ignore missing ends HOT 1
- Optionally include XML declarations and doctype declarations in the DOM
- Streams HOT 2
- 
 is interpreted as space instead of line feed HOT 3
- Parsing can hang on attributes with many references
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parse-xml.