catch db connection error (#345)

This commit is contained in:
JRoberts authored and GitHub committed 2022-04-01 09:52:13 +01:00
1 parent a6ec93c38e
commit bb99fdaaa2
1 file changed
+10 -6
+10 -6
View File
@@ -78,12 +78,16 @@ data SQLiteStore = SQLiteStore
createSQLiteStore :: FilePath -> Int -> [Migration] -> Bool -> IO SQLiteStore
createSQLiteStore dbFilePath poolSize migrations yesToMigrations = do
let dbDir = takeDirectory dbFilePath
createDirectoryIfMissing False dbDir
st <- connectSQLiteStore dbFilePath poolSize
checkThreadsafe st
migrateSchema st migrations yesToMigrations
pure st
createStore
`E.catch` \(e :: E.SomeException) -> putStrLn ("exception: " <> show e) >> E.throwIO e
where
createStore = do
let dbDir = takeDirectory dbFilePath
createDirectoryIfMissing False dbDir
st <- connectSQLiteStore dbFilePath poolSize
checkThreadsafe st
migrateSchema st migrations yesToMigrations
pure st
checkThreadsafe :: SQLiteStore -> IO ()
checkThreadsafe st = withConnection st $ \db -> do