Skip to content

Commit b7b3439

Browse files
authored
Merge pull request #5519 from xmbhasin/err-msg-cli-http
Improve error messages on CLI HTTP request errors
2 parents aad1fdd + daefc1d commit b7b3439

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

CONTRIBUTORS.markdown

+1
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,4 @@ The format for this list: name, GitHub handle
9090
* Brian McKenna (@puffnfresh)
9191
* Ruslan Simchuk (@SimaDovakin)
9292
* Brandon Barker (@bbarker)
93+
* Manish Bhasin (@xmbhasin)

unison-cli/src/Unison/CommandLine/OutputMessages.hs

+22-19
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ import Unison.Term (Term)
138138
import Unison.Term qualified as Term
139139
import Unison.Type (Type)
140140
import Unison.UnisonFile qualified as UF
141+
import Unison.Util.ColorText qualified
141142
import Unison.Util.Conflicted (Conflicted (..))
142143
import Unison.Util.Defn (Defn (..))
143144
import Unison.Util.Defns (Defns (..))
@@ -971,7 +972,6 @@ notifyUser dir = \case
971972
-- defs in the codebase. In some cases it's fine for bindings to
972973
-- shadow codebase names, but you don't want it to capture them in
973974
-- the decompiled output.
974-
975975
let prettyBindings =
976976
P.bracket . P.lines $
977977
P.wrap "The watch expression(s) reference these definitions:"
@@ -1771,16 +1771,16 @@ notifyUser dir = \case
17711771
<> P.newline
17721772
<> P.indentN 2 (P.pshown response)
17731773
Servant.FailureResponse request response ->
1774-
P.wrap "Oops, I received an unexpected status code from the server."
1774+
unexpectedServerResponse response
17751775
<> P.newline
17761776
<> P.newline
1777-
<> P.wrap "Here is the request."
1777+
<> P.wrap "Here is the request:"
17781778
<> P.newline
17791779
<> P.newline
17801780
<> P.indentN 2 (P.pshown request)
17811781
<> P.newline
17821782
<> P.newline
1783-
<> P.wrap "Here is the full response."
1783+
<> P.wrap "Here is the full response:"
17841784
<> P.newline
17851785
<> P.newline
17861786
<> P.indentN 2 (P.pshown response)
@@ -2362,21 +2362,24 @@ prettyTransportError = \case
23622362
Share.RateLimitExceeded -> "Rate limit exceeded, please try again later."
23632363
Share.Timeout -> "The code server timed-out when responding to your request. Please try again later or report an issue if the problem persists."
23642364
Share.UnexpectedResponse resp ->
2365-
(P.lines . catMaybes)
2366-
[ Just
2367-
( "The server sent a "
2368-
<> P.red (P.shown (Http.statusCode (Servant.responseStatusCode resp)))
2369-
<> " that we didn't expect."
2370-
),
2371-
let body = Text.decodeUtf8 (LazyByteString.toStrict (Servant.responseBody resp))
2372-
in if Text.null body then Nothing else Just (P.newline <> "Response body: " <> P.text body),
2373-
responseRequestId resp <&> \responseId -> P.newline <> "Request ID: " <> P.blue (P.text responseId)
2374-
]
2375-
where
2376-
-- Dig the request id out of a response header.
2377-
responseRequestId :: Servant.Response -> Maybe Text
2378-
responseRequestId =
2379-
fmap Text.decodeUtf8 . List.lookup "X-RequestId" . Foldable.toList @Seq . Servant.responseHeaders
2365+
unexpectedServerResponse resp
2366+
2367+
unexpectedServerResponse :: Servant.ResponseF LazyByteString.ByteString -> P.Pretty Unison.Util.ColorText.ColorText
2368+
unexpectedServerResponse resp =
2369+
(P.lines . catMaybes)
2370+
[ Just
2371+
( "I received an unexpected status code from the server: "
2372+
<> P.red (P.shown (Http.statusCode (Servant.responseStatusCode resp)))
2373+
),
2374+
let body = Text.decodeUtf8 (LazyByteString.toStrict (Servant.responseBody resp))
2375+
in if Text.null body then Nothing else Just (P.newline <> "Response body: " <> P.text body),
2376+
responseRequestId resp <&> \responseId -> P.newline <> "Request ID: " <> P.blue (P.text responseId)
2377+
]
2378+
2379+
-- | Dig the request id out of a response header.
2380+
responseRequestId :: Servant.Response -> Maybe Text
2381+
responseRequestId =
2382+
fmap Text.decodeUtf8 . List.lookup "X-RequestId" . Foldable.toList @Seq . Servant.responseHeaders
23802383

23812384
prettyEntityType :: Share.EntityType -> Pretty
23822385
prettyEntityType = \case

0 commit comments

Comments
 (0)