-
Notifications
You must be signed in to change notification settings - Fork 7
Provide parser errors #4
Description
Currently if the parser produces errors when opening a file they are not conveyed to the end-user.
For instance the attached file produces an error and only one IED exists because there is a missing namespace declaration.
We should be alerting the end user to parser errors and provide details as most applications do this (and silent errors like this are quite confusing).
I believe if there are errors, a node, parsererror is created under the root node.
For the above file (in Chrome) this is:
<parsererror xmlns="http://www.w3.org/1999/xhtml" style="display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black"><h3>This page contains the following errors:</h3><div style="font-family:monospace;font-size:12px">error on line 157499 at column 206: Namespace prefix esld for x on IED is not defined
</div><h3>Below is a rendering of the page up to the first error.</h3></parsererror>We could be retrieving this with:
const errorNode = doc.querySelector('parsererror');
if (errorNode) {
errorText = errorNode.textContent
} else {
// parsing succeeded
}If we just use textContent we would get something like:
This page contains the following errors:error on line 157499 at column 206: Namespace prefix esld for x on IED is not defined\nBelow is a rendering of the page up to the first error.
Arguably if the file isn't valid XML we should just barf and refuse to open/process it but I think warning the end user would be better.
A more complete answer might be as described here but I think this might be excessive (?).