Open Bug 1554068 Opened 6 years ago Updated 3 years ago

Dont emit message from DOMParser parseFromString

Categories

(Core :: XML, task)

67 Branch
task

Tracking

()

REOPENED

People

(Reporter: mozilla, Unassigned)

Details

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:67.0) Gecko/20100101 Firefox/67.0

Steps to reproduce:

In console, execute:
try {new DOMParser().parseFromString('INVALID', 'text/xml');} catch (e) {}
or
try {new DOMParser().parseFromString('', 'text/xml');} catch (e) {}

Actual results:

Both print errors:
XML Parsing Error: syntax error
or
XML Parsing Error: no root element found

Expected results:

No error should be printed, due to the try/catch.

Component: Untriaged → Console
Product: Firefox → DevTools

Hello Neil,

So I'm not sure there's a bug.

From the spec:

Parse str using a parser that matches type's supported MIME types (either XML or HTML), and return a Document object contained the parsed content if successful. If not successful, returns a Document describing the error.

You can check that by evaluating the following:

x = (new DOMParser()).parseFromString('INVALID', 'text/xml');
console.log("parsed string:", x);

The console.log call is executed (i.e. parseFromString didn't throw), and print a XmlDocument that you can inspect.
(you can also check on Chrome, which has the same behavior)

Then Firefox emit an error message to warn you that something unexpected happened.

Does that make sense?

Status: UNCONFIRMED → RESOLVED
Closed: 6 years ago
Resolution: --- → INVALID

The problem is with this part:

Then Firefox emit an error message to warn you that something unexpected happened.

I don't want the console populated with the error. I have some code which is purposely parsing xml with an error in it for the purpose of getting the error namespace (which changes from browser to browser). The console warning is not desirable and makes my users think there's an error in my application. Other browsers do not output the error to the console. If the console output is viewed as desirable, there should at least be a way to prevent it when the parsing error is expected and/or handled.

This is the code responsible for logging the warning: https://searchfox.org/mozilla-central/rev/23dd7c485a6525bb3a974abeaafaf34bfb43d76b/parser/htmlparser/nsExpatDriver.cpp#705-722

I'll leave it to the Core:XML owner to decide what we should do with it.

Type: defect → task
Component: Console → XML
Product: DevTools → Core
Summary: DOMParser parseFromString throws error on console despite try/catch → Dont emit message from DOMParser parseFromString
Status: RESOLVED → REOPENED
Ever confirmed: true
Resolution: INVALID → ---

Thanks!

Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.