@@ -4,6 +4,7 @@ module Reporting.Error.Json
5 , FailureToReport(..)
5 , FailureToReport(..)
6 , Context(..)
6 , Context(..)
@@ -23,33 +24,45 @@ import qualified Reporting.Render.Code as Code
23-- TO REPORT
24-- TO REPORT
26−toReport :: FilePath -> FailureToReport x -> Error x -> Help.Report
27+toReport :: FilePath -> FailureToReport x -> Error x -> Reason -> Help.Report
27−toReport path ftr err =
28+toReport path ftr err reason =
28 case err of
29 case err of
29 DecodeProblem bytes problem ->
30 DecodeProblem bytes problem ->
30− problemToReport path ftr (Code.toSource bytes) CRoot problem
31+ problemToReport path ftr (Code.toSource bytes) CRoot problem reason
32 ParseProblem bytes parseError ->
33 ParseProblem bytes parseError ->
33− parseErrorToReport path (Code.toSource bytes) parseError
34+ parseErrorToReport path (Code.toSource bytes) parseError reason
38+ ExplicitReason String
41+because :: Reason -> String -> String
42+because (ExplicitReason iNeedThings) problem =
43+ iNeedThings ++ " " ++ problem
37-- PARSE ERROR TO REPORT
47-- PARSE ERROR TO REPORT
40−parseErrorToReport :: FilePath -> Code.Source -> ParseError -> Help.Report
50+parseErrorToReport :: FilePath -> Code.Source -> ParseError -> Reason -> Help.Report
41−parseErrorToReport path source parseError =
51+parseErrorToReport path source parseError reason =
43− toSnippet title row col pair =
53+ toSnippet title row col (problem, details) =
44 let pos = A.Position row col in
54 let pos = A.Position row col in
45 Help.jsonReport title (Just path) $
55 Help.jsonReport title (Just path) $
46− Code.toSnippet source (A.Region pos pos) Nothing pair
56+ Code.toSnippet source (A.Region pos pos) Nothing
57+ ( D.reflow (because reason problem)
48 case parseError of
61 case parseError of
49 Start row col ->
62 Start row col ->
50 toSnippet "EXPECTING A VALUE" row col
63 toSnippet "EXPECTING A VALUE" row col
52− D.reflow $ "I was expecting to see a JSON value next:"
65+ "I was expecting to see a JSON value next:"
55 [ D.fillSep
68 [ D.fillSep
@@ -66,7 +79,7 @@ parseErrorToReport path source parseError =
66 ObjectField row col ->
79 ObjectField row col ->
67 toSnippet "UNFINISHED OBJECT" row col
80 toSnippet "UNFINISHED OBJECT" row col
69− D.reflow $ "I was partway through parsing a JSON object when I got stuck here:"
82+ "I was partway through parsing a JSON object when I got stuck here:"
72 [ D.reflow $ "I was expecting to see a field name next."
85 [ D.reflow $ "I was expecting to see a field name next."
@@ -77,7 +90,7 @@ parseErrorToReport path source parseError =
77 ObjectColon row col ->
90 ObjectColon row col ->
78 toSnippet "EXPECTING COLON" row col
91 toSnippet "EXPECTING COLON" row col
80− D.reflow $ "I was partway through parsing a JSON object when I got stuck here:"
93+ "I was partway through parsing a JSON object when I got stuck here:"
83 [ D.reflow $ "I was expecting to see a colon next."
96 [ D.reflow $ "I was expecting to see a colon next."
@@ -88,7 +101,7 @@ parseErrorToReport path source parseError =
88 ObjectEnd row col ->
101 ObjectEnd row col ->
89 toSnippet "UNFINISHED OBJECT" row col
102 toSnippet "UNFINISHED OBJECT" row col
91− D.reflow $ "I was partway through parsing a JSON object when I got stuck here:"
104+ "I was partway through parsing a JSON object when I got stuck here:"
94 [ D.reflow $
107 [ D.reflow $
@@ -103,7 +116,7 @@ parseErrorToReport path source parseError =
103 ArrayEnd row col ->
116 ArrayEnd row col ->
104 toSnippet "UNFINISHED ARRAY" row col
117 toSnippet "UNFINISHED ARRAY" row col
106− D.reflow $ "I was partway through parsing a JSON array when I got stuck here:"
119+ "I was partway through parsing a JSON array when I got stuck here:"
109 [ D.reflow $ "I was expecting to see a comma or a closing square bracket next."
122 [ D.reflow $ "I was expecting to see a comma or a closing square bracket next."
@@ -117,8 +130,7 @@ parseErrorToReport path source parseError =
117 BadStringEnd ->
130 BadStringEnd ->
118 toSnippet "ENDLESS STRING" row col
131 toSnippet "ENDLESS STRING" row col
121− "I got to the end of the line without seeing the closing double quote:"
133+ "I got to the end of the line without seeing the closing double quote:"
123 D.fillSep $
135 D.fillSep $
124 ["Strings","look","like",D.green "\"this\"","with","double"
136 ["Strings","look","like",D.green "\"this\"","with","double"
@@ -130,8 +142,7 @@ parseErrorToReport path source parseError =
130 BadStringControlChar ->
142 BadStringControlChar ->
131 toSnippet "UNEXPECTED CONTROL CHARACTER" row col
143 toSnippet "UNEXPECTED CONTROL CHARACTER" row col
134− "I ran into a control character unexpectedly:"
145+ "I ran into a control character unexpectedly:"
136 D.reflow $
147 D.reflow $
137 "These are characters that represent tabs, backspaces, newlines, and\
148 "These are characters that represent tabs, backspaces, newlines, and\
@@ -143,8 +154,7 @@ parseErrorToReport path source parseError =
143 BadStringEscapeChar ->
154 BadStringEscapeChar ->
144 toSnippet "UNKNOWN ESCAPE" row col
155 toSnippet "UNKNOWN ESCAPE" row col
147− "Backslashes always start escaped characters, but I do not recognize this one:"
157+ "Backslashes always start escaped characters, but I do not recognize this one:"
150 [ D.reflow $
160 [ D.reflow $
@@ -159,8 +169,7 @@ parseErrorToReport path source parseError =
159 BadStringEscapeHex ->
169 BadStringEscapeHex ->
160 toSnippet "BAD HEX ESCAPE" row col
170 toSnippet "BAD HEX ESCAPE" row col
163− "This is not a valid hex escape:"
172+ "This is not a valid hex escape:"
165 D.fillSep $
174 D.fillSep $
166 ["Valid","hex","escapes","in","JSON","are","between"
175 ["Valid","hex","escapes","in","JSON","are","between"
@@ -172,7 +181,7 @@ parseErrorToReport path source parseError =
172 NoLeadingZeros row col ->
181 NoLeadingZeros row col ->
173 toSnippet "BAD NUMBER" row col
182 toSnippet "BAD NUMBER" row col
175− D.reflow $ "Numbers cannot start with zeros like this:"
184+ "Numbers cannot start with zeros like this:"
177 D.reflow $ "Try deleting the leading zeros?"
186 D.reflow $ "Try deleting the leading zeros?"
@@ -180,7 +189,7 @@ parseErrorToReport path source parseError =
180 NoFloats row col ->
189 NoFloats row col ->
181 toSnippet "UNEXPECTED NUMBER" row col
190 toSnippet "UNEXPECTED NUMBER" row col
183− D.reflow $ "I got stuck while trying to parse this number:"
192+ "I got stuck while trying to parse this number:"
185 D.reflow $
194 D.reflow $
186 "I do not accept floating point numbers like 3.1415 right now. That kind\
195 "I do not accept floating point numbers like 3.1415 right now. That kind\
@@ -190,7 +199,7 @@ parseErrorToReport path source parseError =
190 BadEnd row col ->
199 BadEnd row col ->
191 toSnippet "JSON PROBLEM" row col
200 toSnippet "JSON PROBLEM" row col
193− D.reflow $ "I was partway through parsing some JSON when I got stuck here:"
202+ "I was partway through parsing some JSON when I got stuck here:"
195 D.reflow $
204 D.reflow $
196 "I am not really sure what is wrong. This sometimes means there is extra\
205 "I am not really sure what is wrong. This sometimes means there is extra\
@@ -224,14 +233,14 @@ data Context
224 | CIndex Int Context
233 | CIndex Int Context
227−problemToReport :: FilePath -> FailureToReport x -> Code.Source -> Context -> Problem x -> Help.Report
236+problemToReport :: FilePath -> FailureToReport x -> Code.Source -> Context -> Problem x -> Reason -> Help.Report
228−problemToReport path ftr source context problem =
237+problemToReport path ftr source context problem reason =
229 case problem of
238 case problem of
230 Field field prob ->
239 Field field prob ->
231− problemToReport path ftr source (CField field context) prob
240+ problemToReport path ftr source (CField field context) prob reason
233 Index index prob ->
242 Index index prob ->
234− problemToReport path ftr source (CIndex index context) prob
243+ problemToReport path ftr source (CIndex index context) prob reason
236 OneOf p ps ->
245 OneOf p ps ->
237 -- NOTE: only displays the deepest problem. This works well for the kind
246 -- NOTE: only displays the deepest problem. This works well for the kind
@@ -239,13 +248,13 @@ problemToReport path ftr source context problem =
240 (NE.List prob _) = NE.sortBy (negate . getMaxDepth) (NE.List p ps)
249 (NE.List prob _) = NE.sortBy (negate . getMaxDepth) (NE.List p ps)
242− problemToReport path ftr source context prob
251+ problemToReport path ftr source context prob reason
244 Failure region x ->
253 Failure region x ->
245 _failureToReport ftr path source context region x
254 _failureToReport ftr path source context region x
247 Expecting region expectation ->
256 Expecting region expectation ->
248− expectationToReport path source context region expectation
257+ expectationToReport path source context region expectation reason
251getMaxDepth :: Problem x -> Int
260getMaxDepth :: Problem x -> Int
@@ -262,8 +271,8 @@ newtype FailureToReport x =
262 FailureToReport { _failureToReport :: FilePath -> Code.Source -> Context -> A.Region -> x -> Help.Report }
271 FailureToReport { _failureToReport :: FilePath -> Code.Source -> Context -> A.Region -> x -> Help.Report }
265−expectationToReport :: FilePath -> Code.Source -> Context -> A.Region -> DecodeExpectation -> Help.Report
274+expectationToReport :: FilePath -> Code.Source -> Context -> A.Region -> DecodeExpectation -> Reason -> Help.Report
266−expectationToReport path source context (A.Region start end) expectation =
275+expectationToReport path source context (A.Region start end) expectation reason =
268 (A.Position sr _) = start
277 (A.Position sr _) = start
269 (A.Position er _) = end
278 (A.Position er _) = end
@@ -289,7 +298,7 @@ expectationToReport path source context (A.Region start end) expectation =
289 toSnippet title aThing =
298 toSnippet title aThing =
290 Help.jsonReport title (Just path) $
299 Help.jsonReport title (Just path) $
291 Code.toSnippet source region Nothing
300 Code.toSnippet source region Nothing
292− ( D.reflow introduction
301+ ( D.reflow (because reason introduction)
293 , D.fillSep $ ["I","was","expecting","to","run","into"] ++ aThing
302 , D.fillSep $ ["I","was","expecting","to","run","into"] ++ aThing