on 1238607 help sign in
104 lines 2.6 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
2module Reporting.Exit.Http
3 ( Exit(..)
4 , toReport
5 , BadJson(..)
6 , badJsonToDocs
7 )
8 where
11import qualified Data.Text as Text
13import Reporting.Doc ((<>))
14import qualified Reporting.Doc as D
15import qualified Reporting.Exit.Help as Help
19-- EXITS
22data Exit
23 = Unknown String
24 | BadJson String D.Doc
25 | BadZipData
26 | BadZipSha String String
30-- TO REPORT
33toReport :: String -> Exit -> Help.Report
34toReport url exit =
35 let
36 urlDoc =
37 D.indent 4 $ D.dullyellow $ "<" <> D.fromString url <> ">"
38 in
39 case exit of
40 Unknown message ->
41 Help.report "HTTP PROBLEM" Nothing "The following HTTP request failed:"
42 [ urlDoc
43 , D.stack
44 [ "Here is the error message I was able to extract:"
45 , D.indent 4 $ D.reflow message
46 ]
47 ]
49 BadJson path doc ->
50 Help.jsonReport "UNEXPECTED JSON" (Just path) doc
52 BadZipData ->
53 Help.report "CORRUPT ZIP" Nothing "I could not unzip the file downloaded from:"
54 [ urlDoc
55 , D.reflow $
56 "If it is a transient issue, it should be fixed if you try this\
57 \ again. If it seems like an Elm problem, please report it though!"
58 ]
60 BadZipSha expectedHash actualHash ->
61 Help.report "CORRUPT ZIP" Nothing "I got an unexpected zip file from:"
62 [ urlDoc
63 , D.reflow "I check the hash the zip, and it seems off:"
64 , D.vcat $ map D.fromString $
65 [ " Expected: " ++ expectedHash
66 , " Actual: " ++ actualHash
67 ]
68 , D.reflow $
69 "This usually means that the package author moved the version\
70 \ tag, so report it to them and see if that is the issue. Folks\
71 \ on Elm slack can probably help as well."
72 ]
76-- BAD JSON
79data BadJson
80 = BadNewPkg Text.Text
81 | BadAllPkg Text.Text String
82 | BadAllVsn Text.Text
85badJsonToDocs :: BadJson -> [D.Doc]
86badJsonToDocs badJson =
87 case badJson of
88 BadNewPkg txt ->
89 ["I","ran","into",D.red (D.fromString (show txt)) <> ","
90 ,"but","I","need","entries","like"
91 ,D.green "\"elm/core@6.0.0\"" <> "."
92 ]
94 BadAllPkg txt suggestion ->
95 ["The",D.red (D.fromString (show txt)),"value","is","not","a","valid","package","name."
96 ]
97 ++ map D.fromString (words suggestion)
99 BadAllVsn txt ->
100 ["You","provided",D.red (D.fromString (show txt))
101 ,"which","is","not","a","valid","version.","I","need","something","like"
102 ,D.green "\"1.0.0\"","or",D.green "\"2.0.4\"" <> "."
103 ]