Add basic error handling to --dump-schema
This commit is contained in:
committed by
Wolfgang Walther
parent
cc54135bf0
commit
af2788468e
+9
-4
@@ -355,15 +355,19 @@ dumpSchema conf =
|
|||||||
(configDbExtraSearchPath conf)
|
(configDbExtraSearchPath conf)
|
||||||
pgVersion
|
pgVersion
|
||||||
(configDbPreparedStatements conf)
|
(configDbPreparedStatements conf)
|
||||||
Right dbStructure <-
|
result <-
|
||||||
timeToStderr "Loaded schema in %.3f seconds" $
|
timeToStderr "Loaded schema in %.3f seconds" $
|
||||||
S.run getDbStructureTransaction conn
|
S.run getDbStructureTransaction conn
|
||||||
C.release conn
|
C.release conn
|
||||||
return $ Aeson.encode dbStructure
|
case result of
|
||||||
|
Left e -> do
|
||||||
|
hPutStrLn stderr $ "An error ocurred when loading the schema cache:\n" <> show e
|
||||||
|
exitFailure
|
||||||
|
Right dbStructure -> return $ Aeson.encode dbStructure
|
||||||
|
|
||||||
|
|
||||||
-- | Print the time taken to run an IO action to stderr with the given printf string
|
-- | Print the time taken to run an IO action to stderr with the given printf string
|
||||||
timeToStderr :: [Char] -> IO a -> IO a
|
timeToStderr :: [Char] -> IO (Either a b) -> IO (Either a b)
|
||||||
timeToStderr fmtString a =
|
timeToStderr fmtString a =
|
||||||
do
|
do
|
||||||
start <- getCPUTime
|
start <- getCPUTime
|
||||||
@@ -372,7 +376,8 @@ timeToStderr fmtString a =
|
|||||||
let
|
let
|
||||||
duration :: Double
|
duration :: Double
|
||||||
duration = fromIntegral (end - start) / picoseconds
|
duration = fromIntegral (end - start) / picoseconds
|
||||||
hPrintf stderr (fmtString ++ "\n") duration
|
when (isRight result) $
|
||||||
|
hPrintf stderr (fmtString ++ "\n") duration
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user