@@ -1,17 +1,20 @@
11{-# OPTIONS_GHC -Wall #-}
22{-# LANGUAGE OverloadedStrings #-}
3−module Reporting.Error where
3+module Reporting.Error
4+ ( Error(..)
5+ , toReports
6+ )
7+ where
48
5−import Data.Aeson ((.=))
6−import qualified Data.Aeson as Json
79
8−import qualified Reporting.Annotation as A
10+import qualified Type.Error
911import qualified Reporting.Error.Canonicalize as Canonicalize
1012import qualified Reporting.Error.Docs as Docs
13+import qualified Reporting.Error.Main as Main
1114import qualified Reporting.Error.Pattern as Pattern
1215import qualified Reporting.Error.Syntax as Syntax
1316import qualified Reporting.Error.Type as Type
14−import qualified Reporting.Render.Type as RenderType
17+import qualified Reporting.Render.Code as Code
1518import qualified Reporting.Report as Report
1619
1720
@@ -20,70 +23,35 @@ import qualified Reporting.Report as Report
2023
2124
2225data Error
23− = Syntax Syntax.Error
24− | Canonicalize Canonicalize.Error
25− | Type Type.Error
26− | Pattern Pattern.Error
27− | Docs Docs.Error
26+ = Syntax Syntax.Error
27+ | Canonicalize Canonicalize.Error
28+ | Type [Type.Error]
29+ | Main Main.Error
30+ | Pattern [Pattern.Error]
31+ | Docs Docs.Error
2832
2933
3034
3135-- TO REPORT
3236
3337
34−toReport :: RenderType.Localizer -> Error -> Report.Report
35−toReport localizer err =
38+toReports :: Code.Source -> Type.Error.Localizer -> Error -> [Report.Report]
39+toReports source localizer err =
3640 case err of
3741 Syntax syntaxError ->
38− Syntax.toReport localizer syntaxError
42+ [Syntax.toReport source syntaxError]
3943
4044 Canonicalize canonicalizeError ->
41− Canonicalize.toReport localizer canonicalizeError
45+ [Canonicalize.toReport source canonicalizeError]
4246
43− Type typeError ->
44− Type.toReport localizer typeError
47+ Type typeErrors ->
48+ map (Type.toReport source localizer) typeErrors
4549
46− Pattern patternError ->
47− Pattern.toReport localizer patternError
50+ Main mainError ->
51+ [Main.toReport source mainError]
52+
53+ Pattern patternErrors ->
54+ map (Pattern.toReport source) patternErrors
4855
4956 Docs docsError ->
50− Docs.toReport 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
57+ [Docs.toReport source docsError]