@@ -96,6 +96,7 @@ import ListT
96import Data.Binary (Binary)
96import Data.Binary (Binary)
97import GHC.Generics (Generic)
97import GHC.Generics (Generic)
98import Control.DeepSeq (force)
98import Control.DeepSeq (force)
99--import Debug.Trace
100--import Debug.Trace
101type Hostname = String
102type Hostname = String
@@ -148,7 +149,7 @@ defaultRemoteConnectionInfo = RemoteProcessConnectionInfo defaultDatabaseName (c
148-- | The 'Connection' represents either local or remote access to a database. All operations flow through the connection.
149-- | The 'Connection' represents either local or remote access to a database. All operations flow through the connection.
149type ClientNodes = STMSet.Set ProcessId
150type ClientNodes = STMSet.Set ProcessId
151−data Connection = InProcessConnection PersistenceStrategy ClientNodes Sessions (TVar TransactionGraph) ScriptSession |
152+data Connection = InProcessConnection PersistenceStrategy ClientNodes Sessions (TVar TransactionGraph) (Maybe ScriptSession) |
152 RemoteProcessConnection LocalNode ProcessId
153 RemoteProcessConnection LocalNode ProcessId
154-- | There are several reasons why a connection can fail.
155-- | There are several reasons why a connection can fail.
@@ -189,6 +190,13 @@ startNotificationListener callback = do
189 Left err -> error ("Failed to start local notification listener: " ++ show err)
190 Left err -> error ("Failed to start local notification listener: " ++ show err)
190 Right localNode -> forkProcess localNode (notificationListener callback)
191 Right localNode -> forkProcess localNode (notificationListener callback)
193+createScriptSession :: [String] -> IO (Maybe ScriptSession)
194+createScriptSession ghcPkgPaths = do
195+ eScriptSession <- initScriptSession ghcPkgPaths
196+ case eScriptSession of
197+ Left err -> hPutStrLn stderr ("Failed to load scripting engine- scripting disabled: " ++ (show err)) >> pure Nothing --not a fatal error, but the scripting feature must be disabled
198+ Right s -> pure (Just s)
192-- | To create a 'Connection' to a remote or local database, create a connectionInfo and call 'connectProjectM36'.
200-- | To create a 'Connection' to a remote or local database, create a connectionInfo and call 'connectProjectM36'.
193connectProjectM36 :: ConnectionInfo -> IO (Either ConnectionError Connection)
201connectProjectM36 :: ConnectionInfo -> IO (Either ConnectionError Connection)
194--create a new in-memory database/transaction graph
202--create a new in-memory database/transaction graph
@@ -203,8 +211,8 @@ connectProjectM36 (InProcessConnectionInfo strat notificationCallback ghcPkgPath
203 clientNodes <- STMSet.newIO
211 clientNodes <- STMSet.newIO
204 sessions <- STMMap.newIO
212 sessions <- STMMap.newIO
205 notificationPid <- startNotificationListener notificationCallback
213 notificationPid <- startNotificationListener notificationCallback
206− interpreterSession <- initScriptSession ghcPkgPaths
214+ mScriptSession <- createScriptSession ghcPkgPaths
207− let conn = InProcessConnection strat clientNodes sessions graphTvar interpreterSession
215+ let conn = InProcessConnection strat clientNodes sessions graphTvar mScriptSession
208 addClientNode conn notificationPid
216 addClientNode conn notificationPid
209 pure (Right conn)
217 pure (Right conn)
210 MinimalPersistence dbdir -> connectPersistentProjectM36 strat NoDiskSync dbdir freshGraph notificationCallback ghcPkgPaths
218 MinimalPersistence dbdir -> connectPersistentProjectM36 strat NoDiskSync dbdir freshGraph notificationCallback ghcPkgPaths
@@ -251,8 +259,8 @@ connectPersistentProjectM36 strat sync dbdir freshGraph notificationCallback ghc
251 tvarGraph <- newTVarIO graph'
259 tvarGraph <- newTVarIO graph'
252 sessions <- STMMap.newIO
260 sessions <- STMMap.newIO
253 clientNodes <- STMSet.newIO
261 clientNodes <- STMSet.newIO
254− scriptSession <- initScriptSession ghcPkgPaths
262+ mScriptSession <- createScriptSession ghcPkgPaths
255− let conn = InProcessConnection strat clientNodes sessions tvarGraph scriptSession
263+ let conn = InProcessConnection strat clientNodes sessions tvarGraph mScriptSession
256 notificationPid <- startNotificationListener notificationCallback
264 notificationPid <- startNotificationListener notificationCallback
257 addClientNode conn notificationPid
265 addClientNode conn notificationPid
258 pure (Right conn)
266 pure (Right conn)