Skip to content
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

Provide parser errors #4

Open
danyill opened this issue Sep 3, 2024 · 0 comments
Open

Provide parser errors #4

danyill opened this issue Sep 3, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@danyill
Copy link

danyill commented Sep 3, 2024

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.

XAT_BusA_P1.cid.zip

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 (?).

@danyill danyill added the enhancement New feature or request label Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant