diff --git a/package.yaml b/package.yaml index d97a5fd08..94278364e 100644 --- a/package.yaml +++ b/package.yaml @@ -1,5 +1,5 @@ -name: simplexmq-legacy -version: 0.5.2 +name: simplexmq-v0 +version: 0.5.3 synopsis: SimpleXMQ message broker description: | This package includes <./docs/Simplex-Messaging-Server.html server>, @@ -71,7 +71,7 @@ executables: - cryptostore == 0.2.* - ini == 0.4.* - optparse-applicative >= 0.15 && < 0.17 - - simplexmq-legacy + - simplexmq-v0 ghc-options: - -threaded @@ -79,7 +79,7 @@ executables: source-dirs: apps/smp-agent main: Main.hs dependencies: - - simplexmq-legacy + - simplexmq-v0 ghc-options: - -threaded @@ -88,7 +88,7 @@ tests: source-dirs: tests main: Test.hs dependencies: - - simplexmq-legacy + - simplexmq-v0 - hspec == 2.7.* - hspec-core == 2.7.* - HUnit == 1.6.* diff --git a/simplexmq-legacy.cabal b/simplexmq-v0.cabal similarity index 96% rename from simplexmq-legacy.cabal rename to simplexmq-v0.cabal index 8e7f5944d..6a30e467a 100644 --- a/simplexmq-legacy.cabal +++ b/simplexmq-v0.cabal @@ -4,8 +4,8 @@ cabal-version: 1.12 -- -- see: https://github.com/sol/hpack -name: simplexmq-legacy -version: 0.5.2 +name: simplexmq-v0 +version: 0.5.3 synopsis: SimpleXMQ message broker description: This package includes <./docs/Simplex-Messaging-Server.html server>, <./docs/Simplex-Messaging-Client.html client> and @@ -37,6 +37,7 @@ library Simplex.Messaging.Agent Simplex.Messaging.Agent.Client Simplex.Messaging.Agent.Env.SQLite + Simplex.Messaging.Agent.ExceptT Simplex.Messaging.Agent.Protocol Simplex.Messaging.Agent.RetryInterval Simplex.Messaging.Agent.Store @@ -57,7 +58,7 @@ library Simplex.Messaging.Transport.WebSockets Simplex.Messaging.Util other-modules: - Paths_simplexmq_legacy + Paths_simplexmq_v0 hs-source-dirs: src ghc-options: -Wall -Wcompat -Werror=incomplete-patterns -Wredundant-constraints -Wincomplete-record-updates -Wincomplete-uni-patterns -Wunused-type-patterns @@ -103,7 +104,7 @@ library executable smp-agent main-is: Main.hs other-modules: - Paths_simplexmq_legacy + Paths_simplexmq_v0 hs-source-dirs: apps/smp-agent ghc-options: -Wall -Wcompat -Werror=incomplete-patterns -Wredundant-constraints -Wincomplete-record-updates -Wincomplete-uni-patterns -Wunused-type-patterns -threaded @@ -134,7 +135,7 @@ executable smp-agent , network-transport ==0.5.* , random >=1.1 && <1.3 , simple-logger ==0.1.* - , simplexmq-legacy + , simplexmq-v0 , sqlite-simple ==0.4.* , stm ==2.5.* , template-haskell ==2.16.* @@ -150,7 +151,7 @@ executable smp-agent executable smp-server main-is: Main.hs other-modules: - Paths_simplexmq_legacy + Paths_simplexmq_v0 hs-source-dirs: apps/smp-server ghc-options: -Wall -Wcompat -Werror=incomplete-patterns -Wredundant-constraints -Wincomplete-record-updates -Wincomplete-uni-patterns -Wunused-type-patterns -threaded @@ -184,7 +185,7 @@ executable smp-server , optparse-applicative >=0.15 && <0.17 , random >=1.1 && <1.3 , simple-logger ==0.1.* - , simplexmq-legacy + , simplexmq-v0 , sqlite-simple ==0.4.* , stm ==2.5.* , template-haskell ==2.16.* @@ -209,7 +210,7 @@ test-suite smp-server-test ServerTests SMPAgentClient SMPClient - Paths_simplexmq_legacy + Paths_simplexmq_v0 hs-source-dirs: tests ghc-options: -Wall -Wcompat -Werror=incomplete-patterns -Wredundant-constraints -Wincomplete-record-updates -Wincomplete-uni-patterns -Wunused-type-patterns @@ -243,7 +244,7 @@ test-suite smp-server-test , network-transport ==0.5.* , random >=1.1 && <1.3 , simple-logger ==0.1.* - , simplexmq-legacy + , simplexmq-v0 , sqlite-simple ==0.4.* , stm ==2.5.* , template-haskell ==2.16.* diff --git a/src/Simplex/Messaging/Agent/Client.hs b/src/Simplex/Messaging/Agent/Client.hs index 48432c945..5069889c9 100644 --- a/src/Simplex/Messaging/Agent/Client.hs +++ b/src/Simplex/Messaging/Agent/Client.hs @@ -54,6 +54,7 @@ import qualified Data.Set as S import Data.Text.Encoding import Data.Time.Clock import Simplex.Messaging.Agent.Env.SQLite +import Simplex.Messaging.Agent.ExceptT () import Simplex.Messaging.Agent.Protocol import Simplex.Messaging.Agent.RetryInterval import Simplex.Messaging.Agent.Store diff --git a/src/Simplex/Messaging/Agent/ExceptT.hs b/src/Simplex/Messaging/Agent/ExceptT.hs new file mode 100644 index 000000000..9fccaaadd --- /dev/null +++ b/src/Simplex/Messaging/Agent/ExceptT.hs @@ -0,0 +1,22 @@ +{-# LANGUAGE InstanceSigs #-} +{-# LANGUAGE RankNTypes #-} +{-# OPTIONS_GHC -fno-warn-orphans #-} + +module Simplex.Messaging.Agent.ExceptT where + +import Control.Monad.Except +import Control.Monad.IO.Unlift +import UnliftIO.Exception (Exception) +import qualified UnliftIO.Exception as E + +newtype InternalException e = InternalException {unInternalException :: e} + deriving (Eq, Show) + +instance Exception e => Exception (InternalException e) + +instance (MonadUnliftIO m, Exception e) => MonadUnliftIO (ExceptT e m) where + withRunInIO :: ((forall a. ExceptT e m a -> IO a) -> IO b) -> ExceptT e m b + withRunInIO exceptToIO = + withExceptT unInternalException . ExceptT . E.try $ + withRunInIO $ \run -> + exceptToIO $ run . (either (E.throwIO . InternalException) return <=< runExceptT) diff --git a/src/Simplex/Messaging/Util.hs b/src/Simplex/Messaging/Util.hs index 0d76781e8..bd5cbbb85 100644 --- a/src/Simplex/Messaging/Util.hs +++ b/src/Simplex/Messaging/Util.hs @@ -1,4 +1,3 @@ -{-# LANGUAGE InstanceSigs #-} {-# LANGUAGE RankNTypes #-} {-# OPTIONS_GHC -fno-warn-orphans #-} @@ -10,20 +9,6 @@ import Data.Bifunctor (first) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import UnliftIO.Async -import UnliftIO.Exception (Exception) -import qualified UnliftIO.Exception as E - -newtype InternalException e = InternalException {unInternalException :: e} - deriving (Eq, Show) - -instance Exception e => Exception (InternalException e) - -instance (MonadUnliftIO m, Exception e) => MonadUnliftIO (ExceptT e m) where - withRunInIO :: ((forall a. ExceptT e m a -> IO a) -> IO b) -> ExceptT e m b - withRunInIO exceptToIO = - withExceptT unInternalException . ExceptT . E.try $ - withRunInIO $ \run -> - exceptToIO $ run . (either (E.throwIO . InternalException) return <=< runExceptT) raceAny_ :: MonadUnliftIO m => [m a] -> m () raceAny_ = r [] diff --git a/tests/AgentTests/SQLiteTests.hs b/tests/AgentTests/SQLiteTests.hs index 725367235..cd73ea295 100644 --- a/tests/AgentTests/SQLiteTests.hs +++ b/tests/AgentTests/SQLiteTests.hs @@ -22,6 +22,7 @@ import Data.Word (Word32) import qualified Database.SQLite.Simple as DB import Database.SQLite.Simple.QQ (sql) import SMPClient (testKeyHash) +import Simplex.Messaging.Agent.ExceptT () import Simplex.Messaging.Agent.Protocol import Simplex.Messaging.Agent.Store import Simplex.Messaging.Agent.Store.SQLite