on aefea20 help sign in
101 lines 2.5 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
12import Text.PrettyPrint.ANSI.Leijen ((<>))
13import qualified Text.PrettyPrint.ANSI.Leijen as P
15import qualified Reporting.Exit.Help as Help
19-- EXITS
22data Exit
23 = Unknown String
24 | BadJson String P.Doc
25 | BadZipData
26 | BadZipSha String String
30-- TO REPORT
33toReport :: String -> Exit -> Help.Report
34toReport url exit =
35 let
36 urlDoc =
37 P.indent 4 $ P.dullyellow $ "<" <> P.text url <> ">"
38 in
39 case exit of
40 Unknown message ->
41 Help.report "HTTP PROBLEM" Nothing "The following HTTP request failed:"
42 [ urlDoc
43 , Help.stack
44 [ "Here is the error message I was able to extract:"
45 , P.indent 4 $ Help.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 , Help.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 , Help.reflow $
64 "I was expecting the hash of content to be " ++ expectedHash
65 ++ ", but it is " ++ actualHash
66 , Help.reflow $
67 "Most likely the package author may have moved the version\
68 \ tag, so report it to them and see if that is the issue."
69 ]
73-- BAD JSON
76data BadJson
77 = BadNewPkg Text.Text
78 | BadAllPkg Text.Text String
79 | BadAllVsn Text.Text
82badJsonToDocs :: BadJson -> [P.Doc]
83badJsonToDocs badJson =
84 case badJson of
85 BadNewPkg txt ->
86 ["I","ran","into",P.red (P.text (show txt)) <> ","
87 ,"but","I","need","entries","like"
88 ,P.green "\"elm-lang/core@6.0.0\"" <> "."
89 ]
91 BadAllPkg txt suggestion ->
92 ["The",P.red (P.text (show txt)),"value","is","not","a","valid","package","name."
93 ]
94 ++ map P.text (words suggestion)
96 BadAllVsn txt ->
97 ["You","provided",P.red (P.text (show txt))
98 ,"which","is","not","a","valid","version.","I","need","something","like"
99 ,P.green "\"1.0.0\"","or",P.green "\"2.0.4\"" <> "."
100 ]