Skip to content

Commit 8b634df

Browse files
committed
Add more logging for endpoint failures
1 parent 1bed518 commit 8b634df

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

src/CLC/Stackage/Parser/API.hs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ import CLC.Stackage.Parser.API.Common
2727
import CLC.Stackage.Parser.API.JSON qualified as JSON
2828
import CLC.Stackage.Utils.Exception qualified as Ex
2929
import CLC.Stackage.Utils.Logging qualified as Logging
30-
import Control.Exception (Exception (displayException))
30+
import Control.Exception (Exception (displayException), throwIO)
3131
import Data.Text qualified as T
3232
import Network.HTTP.Client.TLS qualified as TLS
33+
import System.Exit (ExitCode (ExitFailure))
3334

3435
-- | Returns the 'StackageResponse' corresponding to the given snapshot.
3536
getStackage :: Logging.Handle -> IO StackageResponse
@@ -38,15 +39,25 @@ getStackage hLogger = do
3839
Ex.tryAny (JSON.getStackage manager stackageSnapshot) >>= \case
3940
Right r1 -> pure r1
4041
Left jsonEx -> do
41-
let msg =
42+
let e1 =
4243
mconcat
4344
[ "Json endpoint failed. Trying cabal config next: ",
4445
T.pack $ displayException jsonEx
4546
]
4647

47-
Logging.putTimeWarnStr hLogger msg
48+
Logging.putTimeWarnStr hLogger e1
4849

49-
CabalConfig.getStackage manager stackageSnapshot
50+
Ex.tryAny (CabalConfig.getStackage manager stackageSnapshot) >>= \case
51+
Right r2 -> pure r2
52+
Left ex -> do
53+
let e2 =
54+
mconcat
55+
[ "Cabal config endpoint failed: ",
56+
T.pack $ displayException ex
57+
]
58+
59+
Logging.putTimeErrStr hLogger e2
60+
throwIO $ ExitFailure 1
5061

5162
-- | Stackage snapshot. Currently just 'nightly' to hopefully allow clc-stackage
5263
-- to be more flexible.

0 commit comments

Comments
 (0)