Git Product home page Git Product logo

Comments (7)

g-a-v-i-n avatar g-a-v-i-n commented on July 24, 2024 1

That works for me, thanks!

from parse-xml.

rgrove avatar rgrove commented on July 24, 2024 1

Reopening since there's been a second request for error codes, so it sounds like that may be worth looking into.

from parse-xml.

wooorm avatar wooorm commented on July 24, 2024 1

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.

rgrove avatar rgrove commented on July 24, 2024

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.

g-a-v-i-n avatar g-a-v-i-n commented on July 24, 2024

Thanks for the reply!

Here's the UI I'd ideally like to make using the error you gave as an example.
Frame 23

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.

rgrove avatar rgrove commented on July 24, 2024

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.

rgrove avatar rgrove commented on July 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.