Closed Bug 1808357 Opened 1 year ago Closed 1 year ago

Add better error message for invalid JSON importmap

Categories

(Core :: JavaScript Engine, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
110 Branch
Tracking Status
firefox110 --- fixed

People

(Reporter: nchevobbe, Assigned: allstars.chh)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

Steps to reproduce

  1. Open a tab with data:text/html,<meta charset=utf8> <script type="importmap" >{{"imports": {"square": "./circle.js"}}</script> (note the extra { before imports)
  2. 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)

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.

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!

Severity: -- → S3
Priority: -- → P3

(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: nobody → allstars.chh
Status: NEW → ASSIGNED
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
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 110 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: