1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Reporting.Error.Main
10import qualified Data.Name as Name
12import qualified AST.Canonical as Can
13import qualified Reporting.Annotation as A
14import qualified Reporting.Doc as D
15import qualified Reporting.Error.Canonicalize as E
16import qualified Reporting.Render.Code as Code
17import qualified Reporting.Render.Type as RT
18import qualified Reporting.Render.Type.Localizer as L
19import qualified Reporting.Report as Report
27 = BadType A.Region Can.Type
28 | BadCycle A.Region Name.Name [Name.Name]
29 | BadFlags A.Region Can.Type E.InvalidPayload
36toReport :: L.Localizer -> Code.Source -> Error -> Report.Report
37toReport localizer source err =
39 BadType region tipe ->
40 Report.Report "BAD MAIN TYPE" region [] $
41 Code.toSnippet source region Nothing
43 "I cannot handle this type of `main` value:"
46 [ "The type of `main` value I am seeing is:"
47 , D.indent 4 $ D.dullyellow $ RT.canToDoc localizer RT.None tipe
49 "I only know how to handle Html, Svg, and Programs\
50 \ though. Modify `main` to be one of those types of values!"
54 BadCycle region name names ->
55 Report.Report "BAD MAIN" region [] $
56 Code.toSnippet source region Nothing
58 "A `main` definition cannot be defined in terms of itself."
62 "It should be a boring value with no recursion. But\
63 \ instead it is involved in this cycle of definitions:"
64 , D.cycle 4 name names
68 BadFlags region _badType invalidPayload ->
70 formatDetails (aBadKindOfThing, butThatIsNoGood) =
71 Report.Report "BAD FLAGS" region [] $
72 Code.toSnippet source region Nothing
75 "Your `main` program wants " ++ aBadKindOfThing ++ " from JavaScript."
81 case invalidPayload of
87 "But the exact shape of the record must be known at compile time. No type variables!"
95 "But if I allowed functions from JS, it would be possible to sneak\
96 \ side-effects and runtime exceptions into Elm!"
99 E.TypeVariable name ->
101 "an unspecified type"
104 "But type variables like `" ++ Name.toChars name ++ "` cannot be given as flags.\
105 \ I need to know exactly what type of data I am getting, so I can guarantee that\
106 \ unexpected data cannot sneak in and crash the Elm program."
109 E.UnsupportedType name ->
111 "a `" ++ Name.toChars name ++ "` value"
114 [ D.reflow $ "I cannot handle that. The types that CAN be in flags include:"
117 "Ints, Floats, Bools, Strings, Maybes, Lists, Arrays,\
118 \ tuples, records, and JSON values."
120 "Since JSON values can flow through, you can use JSON encoders and decoders\
121 \ to allow other types through as well. More advanced users often just do\
122 \ everything with encoders and decoders for more control and better errors."
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list