on master help sign in
Improve error messages as described in a list discussion

https://groups.google.com/forum/#!topic/elm-discuss/X4V4edxeFKI

commitb5e731122dc2d34ce8d6e43a1c2869fc603d400f authorEvan Czaplicki <info@elm-lang.org> dateWed 15 Jan 2014, 19:22 (13 years ago) parentb9e627f
1 file changed+13−7
compiler/Type/ExtraChecks.hs+13−7
compiler/Type/ExtraChecks.hs+13−7
@@ -56,7 +56,7 @@ portTypes rules expr =
5656 T.Data ctor ts
5757 | isJs ctor || isElm ctor -> mapM_ valid ts
5858 | ctor == "Signal.Signal" -> handleSignal ts
59− | otherwise -> err "Algebraic Data Types"
59+ | otherwise -> err' True "an unsupported type"
6060
6161 T.Var _ -> err "free type variables"
6262
@@ -90,16 +90,22 @@ portTypes rules expr =
9090 dir inMsg outMsg = case direction of { In -> inMsg ; Out -> outMsg }
9191 txt = P.text . concat
9292
93− err kind =
93+ err = err' False
94+ err' couldBeAlias kind =
9495 throw $
9596 [ txt [ "Type Error: the value ", dir "coming in" "sent out"
9697 , " through port '", name, "' is invalid." ]
97− , txt [ "Acceptable values for ", dir "incoming" "outgoing"
98− , " ports include JavaScript values and the following Elm values:" ]
99− , txt [ "Ints, Floats, Bools, Strings, Maybes, Lists, Tuples, "
100− , dir "" "first-order functions, ", "and concrete records." ]
101− , txt [ "The values sent through this port contain ", kind, ":\n" ]
98+ , txt [ "It contains ", kind, ":\n" ]
10299 , (P.nest 4 . pretty $ Alias.realias rules tipe) <> P.text "\n"
100+ , txt [ "Acceptable values for ", dir "incoming" "outgoing"
101+ , " ports include JavaScript values and" ]
102+ , txt [ "the following Elm values: Ints, Floats, Bools, Strings, Maybes," ]
103+ , txt [ "Lists, Tuples, ", dir "" "first-order functions, ", "and concrete records." ]
104+ ] ++ if couldBeAlias then aliasWarning else []
105+
106+ aliasWarning =
107+ [ txt [ "\nType aliases are not expanded for this check (yet) so you need to do that" ]
108+ , txt [ "manually for now (e.g. {x:Int,y:Int} instead of a type alias of that type)." ]
103109 ]
104110
105111occurs :: (String, Variable) -> StateT TS.SolverState IO ()