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

No args port gives link to irrelevant page #172

Open Ryan1729 opened 8 years ago

Ryan1729 commented 8 years ago

Compiling an elm file like this:

port module Ports exposing (..)

port load : Cmd msg

gives the following error:

-- PORT ERROR ----------------------------------------------------
././Ports.elm

Port `load` has an invalid type.

3| port load : Cmd msg
    ^^^^^^^^^^^^^^^^^^^
You are saying it should be:

    Platform.Cmd.Cmd msg

But you need to use the particular format described here:
<http://guide.elm-lang.org/effect_managers/>

but http://guide.elm-lang.org/effect_managers/ doesn't have any info related to this error on it. I think it would be better if the error message linked to the ports page of the guide and if the possible type signatures were summarized in the error message. AFAICT only one argument ports are allowed so the error message could be something like this:

-- PORT ERROR ----------------------------------------------------
././Ports.elm

Port `load` has an invalid type.

3| port load : Cmd msg
    ^^^^^^^^^^^^^^^^^^^
You are saying it should be:

    Platform.Cmd.Cmd msg

But it should be:
   a -> Platform.Cmd.Cmd msg

   where "a" can be converted to a Javascript value

See here for more info:
<https://guide.elm-lang.org/interop/javascript.html>

This issue also came up before on the mailing list

Also, issues that a change like the one I described could fix have come up on this repo as well:

134

166

Ryan1729 commented 8 years ago

I had a look at the compiler repo and noticed this pull request was already merged. I suppose that fixes most of the problem, but in the particular case of someone trying to use no args at all it seems like a good idea to suggest adding a parameter of () (since AFAICT that's the best solution at this time.)