1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Reporting.Error.Main
10import qualified AST.Canonical as Can
11import qualified Elm.Name as N
12import qualified Reporting.Doc as D
13import qualified Reporting.Error.Canonicalize as E
14import qualified Reporting.Region as R
15import qualified Reporting.Render.Code as Code
16import qualified Reporting.Render.Type as RT
17import qualified Reporting.Render.Type.Localizer as L
18import qualified Reporting.Report as Report
26 = BadType R.Region Can.Type
27 | BadCycle R.Region [N.Name]
28 | BadFlags R.Region Can.Type E.InvalidPayload
35toReport :: L.Localizer -> Code.Source -> Error -> Report.Report
36toReport localizer source err =
38 BadType region tipe ->
39 Report.Report "BAD MAIN TYPE" region [] $
40 Report.toCodeSnippet source region Nothing
42 "I cannot handle this type of `main` value:"
45 [ "The type of `main` value I am seeing is:"
46 , D.indent 4 $ D.dullyellow $ RT.canToDoc localizer RT.None tipe
48 "I only know how to handle Html, Svg, and Programs\
49 \ though. Modify `main` to be one of those types of values!"
53 BadCycle region cycleNames ->
54 Report.Report "BAD MAIN" region [] $
55 Report.toCodeSnippet source region Nothing
57 "A `main` definition cannot be defined in terms of itself."
61 "It should be a boring value with no recursion. But\
62 \ instead it is involved in this cycle of definitions:"
63 , D.cycle 4 cycleNames
67 BadFlags region _badType invalidPayload ->
69 formatDetails (aBadKindOfThing, butThatIsNoGood) =
70 Report.Report "BAD FLAGS" region [] $
71 Report.toCodeSnippet source region Nothing
74 "Your `main` program wants " ++ aBadKindOfThing ++ " from JavaScript."
80 case invalidPayload of
86 "But the exact shape of the record must be known at compile time. No type variables!"
94 "But if I allowed functions from JS, it would be possible to sneak\
95 \ side-effects and runtime exceptions into Elm!"
98 E.TypeVariable name ->
100 "an unspecified type"
103 "But type variables like `" ++ N.toString name ++ "` cannot be given as flags.\
104 \ I need to know exactly what type of data I am getting, so I can guarantee that\
105 \ unexpected data cannot sneak in and crash the Elm program."
108 E.UnsupportedType name ->
110 "a `" ++ N.toString name ++ "` value"
113 [ D.reflow $ "I cannot handle that. The types that CAN be in flags include:"
116 "Ints, Floats, Bools, Strings, Maybes, Lists, Arrays,\
117 \ tuples, records, and JSON values."
119 "Since JSON values can flow through, you can use JSON encoders and decoders\
120 \ to allow other types through as well. More advanced users often just do\
121 \ 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