From bb99fdaaa23a8d537e8add7fd3a22e11960cc860 Mon Sep 17 00:00:00 2001 From: JRoberts <8711996+jr-simplex@users.noreply.github.com> Date: Fri, 1 Apr 2022 12:52:13 +0400 Subject: [PATCH] catch db connection error (#345) --- src/Simplex/Messaging/Agent/Store/SQLite.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Simplex/Messaging/Agent/Store/SQLite.hs b/src/Simplex/Messaging/Agent/Store/SQLite.hs index ff99f04b6..11b737893 100644 --- a/src/Simplex/Messaging/Agent/Store/SQLite.hs +++ b/src/Simplex/Messaging/Agent/Store/SQLite.hs @@ -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