From e0b18b2321758bea237d281bbebd2e1cb8994abe Mon Sep 17 00:00:00 2001 From: Jens Nolte <git@queezle.net> Date: Fri, 8 Oct 2021 01:42:05 +0200 Subject: [PATCH] Move CombinedException to utils --- quasar.cabal | 1 + src/Quasar/ResourceManager.hs | 20 +++++--------------- src/Quasar/Utils/Exceptions.hs | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 15 deletions(-) create mode 100644 src/Quasar/Utils/Exceptions.hs diff --git a/quasar.cabal b/quasar.cabal index 8691cd4..215bd82 100644 --- a/quasar.cabal +++ b/quasar.cabal @@ -94,6 +94,7 @@ library Quasar.Subscribable Quasar.Timer Quasar.Utils.Concurrent + Quasar.Utils.Exceptions Quasar.Utils.ExtraT hs-source-dirs: src diff --git a/src/Quasar/ResourceManager.hs b/src/Quasar/ResourceManager.hs index 6ce2c8f..721f8ef 100644 --- a/src/Quasar/ResourceManager.hs +++ b/src/Quasar/ResourceManager.hs @@ -21,8 +21,6 @@ module Quasar.ResourceManager ( attachDisposeAction_, -- ** Initialization - CombinedException, - combinedExceptions, withRootResourceManager, -- ** Linking computations to a resource manager @@ -32,6 +30,10 @@ module Quasar.ResourceManager ( -- ** Resource manager implementations newUnmanagedRootResourceManager, --newUnmanagedDefaultResourceManager, + + -- * Reexports + CombinedException, + combinedExceptions, ) where @@ -47,6 +49,7 @@ import Quasar.Awaitable import Quasar.Disposable import Quasar.Prelude import Quasar.Utils.Concurrent +import Quasar.Utils.Exceptions data FailedToRegisterResource = FailedToRegisterResource @@ -234,19 +237,6 @@ linkExecution action = do -- ** Root resource manager -newtype CombinedException = CombinedException (NonEmpty SomeException) - deriving stock Show - -instance Exception CombinedException where - displayException (CombinedException exceptions) = intercalate "\n" (header : exceptionMessages) - where - header = mconcat ["CombinedException with ", show (length exceptions), "exceptions:"] - exceptionMessages = (displayException <$> toList exceptions) - -combinedExceptions :: CombinedException -> [SomeException] -combinedExceptions (CombinedException exceptions) = toList exceptions - - data RootResourceManager = RootResourceManager ResourceManager (TVar Bool) (TVar (Maybe (Seq SomeException))) (Awaitable ()) diff --git a/src/Quasar/Utils/Exceptions.hs b/src/Quasar/Utils/Exceptions.hs new file mode 100644 index 0000000..66cbdce --- /dev/null +++ b/src/Quasar/Utils/Exceptions.hs @@ -0,0 +1,21 @@ +module Quasar.Utils.Exceptions ( + CombinedException(..), + combinedExceptions, +) where + +import Control.Exception +import Data.Foldable (toList) +import Data.List.NonEmpty (NonEmpty, nonEmpty) +import Quasar.Prelude + +newtype CombinedException = CombinedException (NonEmpty SomeException) + deriving stock Show + +instance Exception CombinedException where + displayException (CombinedException exceptions) = intercalate "\n" (header : exceptionMessages) + where + header = mconcat ["CombinedException with ", show (length exceptions), "exceptions:"] + exceptionMessages = (displayException <$> toList exceptions) + +combinedExceptions :: CombinedException -> [SomeException] +combinedExceptions (CombinedException exceptions) = toList exceptions -- GitLab