on master help sign in
Update error manager
e63ef23Evan Czaplicki
src/Reporting/Error.hs+26−58
@@ -1,17 +1,20 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3−module Reporting.Error where
3+module Reporting.Error
4+ ( Error(..)
5+ , toReports
6+ )
7+ where
4
8
5−import Data.Aeson ((.=))
6−import qualified Data.Aeson as Json
7
9
8−import qualified Reporting.Annotation as A
10+import qualified Type.Error
9import qualified Reporting.Error.Canonicalize as Canonicalize
11import qualified Reporting.Error.Canonicalize as Canonicalize
10import qualified Reporting.Error.Docs as Docs
12import qualified Reporting.Error.Docs as Docs
13+import qualified Reporting.Error.Main as Main
11import qualified Reporting.Error.Pattern as Pattern
14import qualified Reporting.Error.Pattern as Pattern
12import qualified Reporting.Error.Syntax as Syntax
15import qualified Reporting.Error.Syntax as Syntax
13import qualified Reporting.Error.Type as Type
16import qualified Reporting.Error.Type as Type
14−import qualified Reporting.Render.Type as RenderType
17+import qualified Reporting.Render.Code as Code
15import qualified Reporting.Report as Report
18import qualified Reporting.Report as Report
16
19
17
20
@@ -20,70 +23,35 @@ import qualified Reporting.Report as Report
20
23
21
24
22data Error
25data Error
23− = Syntax Syntax.Error
26+ = Syntax Syntax.Error
24− | Canonicalize Canonicalize.Error
27+ | Canonicalize Canonicalize.Error
25− | Type Type.Error
28+ | Type [Type.Error]
29+ | Main Main.Error
26− | Pattern Pattern.Error
30+ | Pattern [Pattern.Error]
27− | Docs Docs.Error
31+ | Docs Docs.Error
28
32
29
33
30
34
31-- TO REPORT
35-- TO REPORT
32
36
33
37
34−toReport :: RenderType.Localizer -> Error -> Report.Report
38+toReports :: Code.Source -> Type.Error.Localizer -> Error -> [Report.Report]
35−toReport localizer err =
39+toReports source localizer err =
36 case err of
40 case err of
37 Syntax syntaxError ->
41 Syntax syntaxError ->
38− Syntax.toReport localizer syntaxError
42+ [Syntax.toReport source syntaxError]
39
43
40 Canonicalize canonicalizeError ->
44 Canonicalize canonicalizeError ->
41− Canonicalize.toReport localizer canonicalizeError
45+ [Canonicalize.toReport source canonicalizeError]
42
46
43− Type typeError ->
47+ Type typeErrors ->
44− Type.toReport localizer typeError
48+ map (Type.toReport source localizer) typeErrors
45
49
46− Pattern patternError ->
50+ Main mainError ->
51+ [Main.toReport source mainError]
52+
53+ Pattern patternErrors ->
47− Pattern.toReport localizer patternError
54+ map (Pattern.toReport source) patternErrors
48
55
49 Docs docsError ->
56 Docs docsError ->
50− Docs.toReport docsError
57+ [Docs.toReport source docsError]
51−
52−
53−
54−-- TO JSON
55−
56−
57−toJson :: RenderType.Localizer -> FilePath -> A.Located Error -> Json.Value
58−toJson localizer filePath (A.A region err) =
59− let
60− (maybeRegion, additionalFields) =
61− case err of
62− Syntax syntaxError ->
63− Report.toJson [] (Syntax.toReport localizer syntaxError)
64−
65− Canonicalize canonicalizeError ->
66− let
67− suggestions =
68− maybe []
69− (\s -> ["suggestions" .= s])
70− (Canonicalize.extractSuggestions canonicalizeError)
71− in
72− Report.toJson suggestions (Canonicalize.toReport localizer canonicalizeError)
73−
74− Type typeError ->
75− Report.toJson [] (Type.toReport localizer typeError)
76−
77− Pattern patternError ->
78− Report.toJson [] (Pattern.toReport localizer patternError)
79−
80− Docs docsError ->
81− Report.toJson [] (Docs.toReport docsError)
82− in
83− Json.object $
84− [ "file" .= filePath
85− , "region" .= region
86− , "subregion" .= maybeRegion
87− , "type" .= ("error" :: String)
88− ]
89− ++ additionalFields