elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.51k stars 657 forks source link

Compiler hangs forever if elm.json's dependencies field is an empty object #2109

Open jfmengels opened 4 years ago

jfmengels commented 4 years ago

Quick Summary: When the elm.json's "dependencies" field is {} instead of { "direct": { ... }, "indirect": { ... } }, the compiler tries to explain the problem, but hangs in the process

SSCCE

Compile any Elm code with the following command elm make A.elm and with the following elm.json file:

{
    "type": "application",
    "source-directories": [
        "."
    ],
    "elm-version": "0.19.1",
    "dependencies": {},
    "test-dependencies": {
        "direct": {},
        "indirect": {}
    }
}
-- Elm code is barely important here
module A exposing (a)
a = 1

Additional Details

This is the message I get:

> elm make A.elm
Dependencies ready!         
-- MISSING FIELD ------------------------------------------------------ elm.json

I ran into a problem with your elm.json file. I ran into trouble with the value
of the "dependencies" field:

Then it hangs forever and takes 100% of one of my thread's CPU until I kill the process.

For context: I get this error when trying to programmatically create an elm.json in elm-review (kind of like elm-test does it). I use elm-json to know which dependencies need to be added to elm-json, but that fails when the user has no Internet access.

I should be able to go around this problem without too much trouble, but I thought it might be useful to know that this problem exists.

github-actions[bot] commented 4 years ago

Thanks for reporting this! To set expectations:

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

lydell commented 2 years ago

Here’s something interesting: If I make the following change to the SSCCE:

-    "dependencies": {},
+    "dependencies": {
+    },

Then I get the expected error message with no hanging:

-- MISSING FIELD ------------------------------------------------------ elm.json

I ran into a problem with your elm.json file. I ran into trouble with the value
of the "dependencies" field:

7|     "dependencies": {
                       ^
I was expecting to run into an OBJECT with a "direct" field.

I think that the error reporting hangs whenever the JSON syntax is correct but there’s an error like “missing field” in a JSON object written on a single line.

This is the shortest reproduction I could come up with:

❯ mkdir elm-hang
❯ cd elm-hang
❯ echo '{}' > elm.json
❯ elm make
Dependencies ready!
-- MISSING FIELD ------------------------------------------------------ elm.json

I ran into a problem with your elm.json file. I ran into some trouble here:

^C^C⏎

However, if you do printf '{\n}' > elm.json instead of echo '{}' > elm.json, it does not hang:

Dependencies ready!
-- MISSING FIELD ------------------------------------------------------ elm.json

I ran into a problem with your elm.json file. I ran into some trouble here:

1| {
   ^
I was expecting to run into an OBJECT with a "type" field.

Note: If you’re messing around with this, don’t forget to remove the elm-stuff/ folder before each elm make run! Otherwise the bug might not occur.