Add better error message for invalid JSON importmap
Categories
(Core :: JavaScript Engine, enhancement, P3)
Tracking
()
Tracking | Status | |
---|---|---|
firefox110 | --- | fixed |
People
(Reporter: nchevobbe, Assigned: allstars.chh)
References
(Blocks 1 open bug)
Details
Attachments
(1 file)
Steps to reproduce
- Open a tab with
data:text/html,<meta charset=utf8> <script type="importmap" >{{"imports": {"square": "./circle.js"}}</script>
(note the extra{
beforeimports
) - Open the console
Result
The following error message appears in the console:
Uncaught SyntaxError: JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data
While it's better than nothing, it could be hard to understand this relates to the importmap being invalid.
For what it's worth, Chrome prints the following:
Uncaught SyntaxError: Failed to parse import map: invalid JSON
Our Learn more
link could point to https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap (but that can be a follow up for the DevTools team)
Assignee | ||
Comment 1•1 year ago
|
||
Hi Nicolas
Can you clarify "The better error message"?
IMO, our JSON parser provides more detailed information like lineno and columnno,
when the import map text is long, it would be pretty helpful.
With simply "invalid JSON", you still don't know where it went wrong.
Comment 2•1 year ago
|
||
A custom error message here for the case of JSON decoding for the purpose of an ImportMap does seem like a user experience improvement -- we should keep the line and col numbers tho!
Updated•1 year ago
|
Reporter | ||
Comment 3•1 year ago
|
||
(In reply to Yoshi Cheng-Hao Huang [:allstars.chh][:allstarschh][:yoshi] from comment #1)
Hi Nicolas
Can you clarify "The better error message"?
IMO, our JSON parser provides more detailed information like lineno and columnno,
when the import map text is long, it would be pretty helpful.With simply "invalid JSON", you still don't know where it went wrong.
we could do something like
Uncaught SyntaxError: Failed to parse import map: invalid JSON, expected property name or '}' at line 1 column 2 of the JSON data
Assignee | ||
Comment 4•1 year ago
|
||
Updated•1 year ago
|
Pushed by allstars.chh@gmail.com: https://hg.mozilla.org/integration/autoland/rev/05d23ba4b590 Add better error message for importmaps of invalid JSON format. r=jonco
Comment 6•1 year ago
|
||
bugherder |
Description
•