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

--report json prints invalid JSON on "NO TABS" error #2259

Open
lydell opened this issue May 7, 2022 · 1 comment
Open

--report json prints invalid JSON on "NO TABS" error #2259

lydell opened this issue May 7, 2022 · 1 comment

Comments

@lydell
Copy link
Contributor

lydell commented May 7, 2022

Quick Summary: --report json prints invalid JSON on "NO TABS" error

SSCCE

# Start a fresh project.
❯ elm init

# Create an Elm file with a single tab character in it.
# (Tab characters are not allowed in Elm source code.)
❯ printf '\t' > Main.elm

# Type check with JSON output, and try to parse that with Node.js.
❯ elm make --output /dev/null Main.elm --report json 2>&1 | node -p 'JSON.parse(fs.readFileSync(process.stdin.fd, "utf8"))'
undefined:1
{"type":"compile-errors","errors":[{"path":"Main.elm","name":"???","problems":[{"title":"NO TABS","region":{"start":{"line":1,"column":1},"end":{"line":1,"column":1}},"message":["I ran into a tab, but tabs are not allowed in Elm files.\n\n1| 	\n   ",{"bold":false,"underline":false,"color":"RED","string":"^"},"\nReplace the tab with spaces."]}]}]}
                                                                                                                                                                                                                                                  ^

SyntaxError: Unexpected token 	 in JSON at position 242
    at JSON.parse (<anonymous>)
    at [eval]:1:6
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:305:38)
    at node:internal/process/execution:76:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:75:60)
    at node:internal/main/eval_string:27:3

# Workaround: Replace all tab characters with \t.
❯ elm make --output /dev/null Main.elm --report json 2>&1 | node -p 'JSON.parse(fs.readFileSync(process.stdin.fd, "utf8").replace(/\t/g, "\\\\t"))'
{
  type: 'compile-errors',
  errors: [ { path: 'Main.elm', name: '???', problems: [Array] } ]
}
  • Elm: 0.19.1
  • Browser: I’ve tested Firefox, Chrome and Safari (as well as Node.js), and they all follow the spec and throw a parse error on JSON.parse(`"\t"`).
  • Operating System: macOS Monterey, but it shouldn’t matter

Additional Details

The JSON spec (see the sidebar to the right) defines a JSON string as:

string
    '"' characters '"'

characters
    ""
    character characters

character
    '0020' . '10FFFF' - '"' - '\'
    '\' escape

As you can see, a “character” can be anything from U 0020 (regular space) to U 10FFFF, except double quote and backslash (because of escapes). (How to read that syntax.) A tab character is U 0009, which is outside of that range.

Here’s a StackOverflow answer discussing tabs in JSON

Luckily, consumers of --report json can replace literal tab characters with \t and then parse.

@github-actions
Copy link

github-actions bot commented May 7, 2022

Thanks for reporting this! To set expectations:

  • Issues are reviewed in batches, so it can take some time to get a response.
  • Ask questions in a community forum. You will get an answer quicker that way!
  • If you experience something similar, open a new issue. We like duplicates.

Finally, please be patient with the core team. They are trying their best with limited resources.

lydell added a commit to lydell/elm-watch that referenced this issue May 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant