Correct --dump-schema swallowing error

When there's no connection to pg, the following error happens
when running --dump-schema:

postgrest: user error (Pattern match failure in do expression at
main/Main.hs:361:5-14)

Now it shows a regular "could not connect to server.." error.
This commit is contained in:
steve-chavez
2021-01-19 13:49:40 -05:00
committed by Steve Chavez
parent 15039553db
commit 674615041a
+10 -8
View File
@@ -28,7 +28,8 @@ import Data.Time.Clock (getCurrentTime)
import Network.Wai.Handler.Warp (defaultSettings, runSettings, import Network.Wai.Handler.Warp (defaultSettings, runSettings,
setHost, setPort, setServerName) setHost, setPort, setServerName)
import System.CPUTime (getCPUTime) import System.CPUTime (getCPUTime)
import System.IO (BufferMode (..), hSetBuffering) import System.IO (BufferMode (..), hPrint,
hSetBuffering)
import Text.Printf (hPrintf) import Text.Printf (hPrintf)
import PostgREST.App (postgrest) import PostgREST.App (postgrest)
@@ -345,19 +346,20 @@ reReadConfig env path refConf = do
dumpSchema :: AppConfig -> IO LBS.ByteString dumpSchema :: AppConfig -> IO LBS.ByteString
dumpSchema conf = dumpSchema conf =
do do
Right conn <- C.acquire . toS $ configDbUri conf eitherConn <- C.acquire . toS $ configDbUri conf
Right pgVersion <- S.run getPgVersion conn case eitherConn of
let Left e -> hPrint stderr e >> exitFailure
getDbStructureTransaction = Right conn -> do
result <-
timeToStderr "Loaded schema in %.3f seconds" $
flip S.run conn $ do
pgVersion <- getPgVersion
HT.transaction HT.ReadCommitted HT.Read $ HT.transaction HT.ReadCommitted HT.Read $
getDbStructure getDbStructure
(toList $ configDbSchemas conf) (toList $ configDbSchemas conf)
(configDbExtraSearchPath conf) (configDbExtraSearchPath conf)
pgVersion pgVersion
(configDbPreparedStatements conf) (configDbPreparedStatements conf)
result <-
timeToStderr "Loaded schema in %.3f seconds" $
S.run getDbStructureTransaction conn
C.release conn C.release conn
case result of case result of
Left e -> do Left e -> do