on c299dfe help sign in
102 lines 2.5 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Reporting.Error.Http
4 ( Error(..)
5 , toReport
6 , BadJson(..)
7 , badJsonToDocs
8 )
9 where
12import qualified Data.Text as Text
13import Text.PrettyPrint.ANSI.Leijen ((<>))
14import qualified Text.PrettyPrint.ANSI.Leijen as P
16import qualified Reporting.Error.Help as Help
20-- ERRORS
23data Error
24 = Unknown String
25 | BadJson P.Doc
26 | BadZipData
27 | BadZipSha String String
31-- TO REPORT
34toReport :: String -> Error -> Help.Report
35toReport url err =
36 let
37 urlDoc =
38 P.indent 4 $ P.dullyellow $ "<" <> P.text url <> ">"
39 in
40 case err of
41 Unknown message ->
42 Help.report "HTTP PROBLEM" Nothing "The following HTTP request failed:"
43 [ urlDoc
44 , Help.stack
45 [ "Here is the error message I was able to extract:"
46 , P.indent 4 $ Help.reflow message
47 ]
48 ]
50 BadJson jsonErrorDoc ->
51 Help.compilerReport jsonErrorDoc
53 BadZipData ->
54 Help.report "CORRUPT ZIP" Nothing "I could not unzip the file downloaded from:"
55 [ urlDoc
56 , Help.reflow $
57 "If it is a transient issue, it should be fixed if you try this\
58 \ again. If it seems like an Elm problem, please report it though!"
59 ]
61 BadZipSha expectedHash actualHash ->
62 Help.report "CORRUPT ZIP" Nothing "I got an unexpected zip file from:"
63 [ urlDoc
64 , Help.reflow $
65 "I was expecting the hash of content to be " ++ expectedHash
66 ++ ", but it is " ++ actualHash
67 , Help.reflow $
68 "Most likely the package author may have moved the version\
69 \ tag, so report it to them and see if that is the issue."
70 ]
74-- BAD JSON
77data BadJson
78 = BadNewPkg Text.Text
79 | BadAllPkg Text.Text String
80 | BadAllVsn Text.Text
83badJsonToDocs :: BadJson -> [P.Doc]
84badJsonToDocs badJson =
85 case badJson of
86 BadNewPkg txt ->
87 ["I","ran","into",P.red (P.text (show txt)) <> ","
88 ,"but","I","need","entries","like"
89 ,P.green "\"elm-lang/core@6.0.0\"" <> "."
90 ]
92 BadAllPkg txt suggestion ->
93 ["The",P.red (P.text (show txt)),"value","is","not","a","valid","package","name."
94 ]
95 ++ map P.text (words suggestion)
97 BadAllVsn txt ->
98 ["You","provided",P.red (P.text (show txt))
99 ,"which","is","not","a","valid","version.","I","need","something","like"
100 ,P.green "\"1.0.0\"","or",P.green "\"2.0.4\"" <> "."
101 ]