isaacs / sax-js

A sax style parser for JS
Other
1.09k stars 325 forks source link

Add error location properties to parser error #220

Open marekweb opened 6 years ago

marekweb commented 6 years ago

Currently when there's a parser error, the location of the error is appended as a string to the error message.

Error: Unexpected close tag
Line: 0
Column: 17
Char: >

It would be useful to provide the location as a set of properties on the object.

{
  line: 0,
  column: 17,
  char: '>'
}

Use cases:

Better error reporting. Allow the possibility of excerpting the XML input to show the location of the error.

parser.onerror = function(error) {
  console.error('Parsing error at location: ' + error.line + ':' + error.column)
}