theintern / intern

A next-generation code testing stack for JavaScript.
https://theintern.io/
Other
4.36k stars 310 forks source link

Show better errors for invalid JSON #1097

Open jason0x43 opened 4 years ago

jason0x43 commented 4 years ago

When parsing JSON data, such as a config files or JSON messages received from remotes, Intern doesn't provide much information about errors in the data. For example, Intern currently shows an error like this for an invalid config:

Error: Invalid JSON in /Users/jason/Documents/Work/src/intern/intern/intern.json
    at /Users/jason/Documents/Work/src/intern/intern/_testIntern/core/lib/common/util.js:665:19

This is what default JSON parse errors look like:

SyntaxError: Unexpected token h in JSON at position 0
  at JSON.parse @ anonymous

The message emitted by Intern should indicate specifically where the problem is, and display a relevant snippet of the data. For example, if the config contained this:

    "reporters": {
      "name": "runner",
      "options": { "hideSkipped": false, "hidePassed": '.' }
    },

Intern should parse that and display a friendly error. One possibility would be

Error: Unexpected character in config file "intern.json"

>  "reporters": {
>    "name": "runner",
>    "options": { "hideSkipped": false, "hidePassed": '.' }
                                                      ^

Intern could also employ syntax highlighting to change the color or font weight of the erroneous character.