elm / error-message-catalog

A catalog of broken Elm programs / data to improve error messages
BSD 3-Clause "New" or "Revised" License
174 stars 17 forks source link

SSCCE for line number of declaration in missing whitespace scenario #196

Closed brunogirin closed 5 years ago

brunogirin commented 7 years ago

As described in issue #164, the compiler does not provide a line number when some syntax errors occur, in particular when it encounters missing closing brackets. When compiling the attached file, the compiler provides the following message:

$ elm make WhitespaceSscce.elm 
-- SYNTAX PROBLEM ------------------------------------------ WhitespaceSscce.elm

I need whitespace, but got stuck on what looks like a new declaration. You are
either missing some stuff in the declaration above or just need to add some
spaces here:

I am looking for one of the following things:

    whitespace

Detected errors in 1 module.                                        

Although the problem is obvious in the attached example, it can be very difficult to find the offending line in a complex module so it would help enormously if the compiler could provide the line number where the error was found or the line number where the declaration that it was trying to parse is.

WhitespaceSscce.zip

domenkozar commented 6 years ago

SSCCE:

$ cat foo.elm
module WhiteSpace exposing (..)

broken : List String
broken =
 [ "aa"
 , "asd"
 [ "asd"
 , "bla"
 ]
$ elm make foo.elm
-- SYNTAX PROBLEM ------------------------------------------------------ foo.elm                      

I need whitespace, but got stuck on what looks like a new declaration. You are
either missing some stuff in the declaration above or just need to add some
spaces here:                             

I am looking for one of the following things:

    whitespace         
evancz commented 5 years ago

Thanks for the report! I have made a bunch of improvements to parse errors, so in the development build @domenkozar's SSCCE is producing:

-- UNFINISHED LIST ---------------------------------------------------- temp.elm

I cannot find the end of this list:

5|  [ "aa"
6|  , "asd"
7|  [ "asd"
8|  , "bla"
9|  ]
     ^
You can just add a closing ] right here, and I will be all set!

Note: I may be confused by indentation. For example, if you are trying to define
a list across multiple lines, I recommend using this format:

    [ "Alice"
    , "Bob"
    , "Chuck"
    ]

Notice that nothing comes directly after a newline. Each line starts with some
spaces. This style can be jarring for people coming from C-like syntax, but
folks generally report that they are used to it (and often prefer it!) after a
week or two of using Elm.

Much more specific to what is going on in this case. This should become available once Elm 0.19.1 is released.