on master help sign in
Create nicely formatted error messages
b4a568cEvan Czaplicki
src/Elm/Compiler.hs+3−3
@@ -83,9 +83,9 @@ compile user packageName source interfaces =
83newtype Error = Error (A.Located Error.Error)
83newtype Error = Error (A.Located Error.Error)
84
84
85
85
86−errorToString :: Error -> String
86+errorToString :: String -> String -> Error -> String
87−errorToString (Error err) =
87+errorToString location source (Error err) =
88− Error.toString err
88+ Error.toString location source err
89
89
90
90
91errorToJson :: Error -> String
91errorToJson :: Error -> String
src/Reporting/Error.hs+30−9
@@ -9,6 +9,7 @@ import qualified Reporting.Annotation as A
9import qualified Reporting.Error.Canonicalize as Canonicalize
9import qualified Reporting.Error.Canonicalize as Canonicalize
10import qualified Reporting.Error.Syntax as Syntax
10import qualified Reporting.Error.Syntax as Syntax
11import qualified Reporting.Error.Type as Type
11import qualified Reporting.Error.Type as Type
12+import qualified Reporting.Region as R
12
13
13
14
14-- ALL POSSIBLE ERRORS
15-- ALL POSSIBLE ERRORS
@@ -21,17 +22,37 @@ data Error
21
22
22-- TO STRING
23-- TO STRING
23
24
24−toString :: A.Located Error -> String
25+toString :: String -> String -> A.Located Error -> String
25−toString (A.A region err) =
26+toString location source (A.A region err) =
27+ let
28+ (tag, hint) =
26− case err of
29+ case err of
27− Syntax syntaxError ->
30+ Syntax syntaxError ->
31+ ( "SYNTAX ERROR"
28− error "TODO" syntaxError
32+ , Syntax.toHint syntaxError
33+ )
29
34
30− Canonicalize canonicalizeError ->
35+ Canonicalize canonicalizeError ->
36+ ( "NAMING ERROR"
31− Canonicalize.toString region canonicalizeError
37+ , Canonicalize.toHint canonicalizeError
38+ )
32
39
33− Type typeError ->
40+ Type typeError ->
34− Type.toString region typeError
41+ ( "TYPE ERROR"
42+ , Type.toHint typeError
43+ )
44+
45+ usedSpace =
46+ 4 + length tag + length location + 4
47+
48+ messageBar =
49+ "-- " ++ tag ++ " "
50+ ++ replicate (max 1 (80 - usedSpace)) '-'
51+ ++ " " ++ location ++ " --"
52+ in
53+ messageBar ++ "\n\n"
54+ ++ R.select region source ++ "\n"
55+ ++ hint ++ "\n\n"
35
56
36
57
37-- JSON
58-- JSON
src/Reporting/Region.hs+1−1
@@ -93,7 +93,7 @@ select (Region start end) source =
93 [line start .. line end]
93 [line start .. line end]
94 focusedRelevantLines
94 focusedRelevantLines
95 in
95 in
96− unlines numberedLines
96+ unlines numberedLines ++ "\n"
97
97
98
98
99addLineNumber :: Int -> Int -> String -> String
99addLineNumber :: Int -> Int -> String -> String