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

Throws exception when parsing invalid string #224

Open
newmanw opened this issue Apr 20, 2021 · 1 comment
Open

Throws exception when parsing invalid string #224

newmanw opened this issue Apr 20, 2021 · 1 comment
Labels
documentation Improvements or additions to documentation spec:no standard

Comments

@newmanw
Copy link

newmanw commented Apr 20, 2021

When parsing an invalid file I have to wrap in a try/catch block.

  try {
    const document = new DOMParser().parseFromString(data);
  } catch (err) {
    // Parse error
  }

This seems to go against the spec: https://developer.mozilla.org/en-US/docs/Web/API/DOMParser/parseFromString#error_handling

Not a huge deal, however this is not documented. If this is indeed the intent, the docs should be updated.

@karfau karfau added documentation Improvements or additions to documentation help-wanted External contributions welcome spec:no standard labels Apr 20, 2021
@karfau
Copy link
Member

karfau commented Apr 20, 2021

Thanks for pointing it out. You are totally right that we need to document this, since error handling in general doesn't work like in any spec.

Ps: The good thing is that xmldom offers an API, so you are in control, some (very small and vague) part of it is documented in the readme (search for errorHandler. You can override the error handling and specify what to do in case of fatalErrors (the ones that throw), errors (only logged by default) and warnings. It's also on option to ignore them in case you pass a noop (() => {}).
There are also quite some tests on the topic that might help you understand how it works.

@karfau karfau removed the help-wanted External contributions welcome label Aug 23, 2021
@karfau karfau added this to the planning 1.0.0 milestone Aug 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation spec:no standard
Projects
None yet
Development

No branches or pull requests

2 participants