elm / error-message-catalog

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

Which error messages should exist? #320

Open CSDUMMI opened 4 years ago

CSDUMMI commented 4 years ago

In many programs, you have many functions (init,update,view, etc.) and especially using elm/browser, you first use these function's name and then define them:

main = Browser.sandbox { init = init, update = update, view = view }

-- MODEL
init = ...
-- UPDATE
update = ...
-- VIEW
view = ...

Now, how do you start programming? One function, after the other, I'd think. I got an example: (this is the entire file, I didn't cut it off at the end)

module Main exposing (..)

import Browser

-- MAIN
main = Browser.sandbox { init = init, update = update, view = view }

-- MODEL
type alias Model = Int

init : Model
init = 0
-- UPDATE
type Msg
  = Inc
  | Dec

update : Msg -> Model -> Model
update msg model = case msg of
  Inc -> model +1

-- VIEW

Two things, that you'll notice:

Which error would be most helpful for you?

If I simply compile this file I get:

Detected problems in 1 module.
-- NAMING ERROR --------------------------------------------------- src/Main.elm

I cannot find a `view` variable:

6| main = Browser.sandbox { init = init, update = update, view = view }
                                                                 ^^^^
These names seem close though:

    e
    min
    pi
    sin

Hint: Read <https://elm-lang.org/0.19.1/imports> to see how `import`
declarations work in Elm.

If I add a definition of view I get:

Detected problems in 1 module.
-- MISSING PATTERNS ----------------------------------------------- src/Main.elm

This `case` does not have branches for all possibilities:

21|>update msg model = case msg of
22|>  Inc -> model +1

Missing possibilities include:

    Dec

I would have to crash if I saw one of those. Add branches for them!

Hint: If you want to write the code for each branch later, use `Debug.todo` as a
placeholder. Read <https://elm-lang.org/0.19.1/missing-patterns> for more
guidance on this workflow.

I think, if both were shown, it would be more helpful

Thus I'd think, that the second one should at least printed, because it is more important for me, I know that view isn't defined yet, but I want to know what I forgot in update.

CSDUMMI commented 4 years ago

May I add, that this isn't just about the order of error messages, but also about their mere existence.