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 656 forks source link

Proposal: Better error message for lack of "main" function #1198

Closed stormont closed 8 years ago

stormont commented 8 years ago

I was running through the elm-architecture example with core 0.16 and I ran into a situation where I was compiling without a "main" function defined (intentionally; I was trying to catch other compile errors). But, the output I got wouldn't provide much guidance to someone with expectations of a full compile:

> elm-make Main.elm
-- SYNTAX PROBLEM ----------------------------------------------------- Main.elm

I ran into something unexpected when parsing your code!

I am looking for one of the following things:

    "{-|"
    a port declaration
    a type declaration
    a value definition
    an import
    an infix declaration

Detected errors in 1 module.

I know that elm-make allows more distinct module-level compilations, but in this case, I was using the default options, which will assume a "main" function (or, presumably, some combination of other declarations, as reported by the output).

It might be helpful to suggest "Did you forget to create a main declaration?" or something of that sort.

igrep commented 8 years ago

You mean you tried to compile such a source?

module Main where

import App

import StartApp.Simple

-- EOF here --

Actually, a module can be compiled without main declaration. So, it might be good to hint that a module must have one or more type or value definition.

mgold commented 8 years ago

Yes, a module needs to define at least one thing. It would be good to have a better error message, but the current one isn't terrible: it's looking for you to define or declare some things.

stormont commented 8 years ago

Yes, sorry, I didn't explain this as well as I could have (I was kind of tired when I wrote this up). I'm really just asking for a more helpful error message. I had done something just like @igrep asked about to generate the error (just module declaration + imports).

evancz commented 8 years ago

Can we move this to https://github.com/elm-lang/error-message-catalog/issues where we track "bad error messages" such that it's easy to see connections and categories of things to improve?

When it is moved, please look around for similar things. If you don't see anything, be sure to put a http://sscce.org in the initial description. If we have the exact source code you used to get that error, it'll be much easier to fix the thing you saw. No chance of confusion!