componentm 0.0.0.1 → 0.0.0.2
raw patch · 5 files changed
+89/−14 lines, 5 filesdep +pretty-showPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
Dependencies added: pretty-show
API changes (from Hackage documentation)
+ Control.Monad.Component: ComponentErrorDetected :: !ComponentError -> ComponentEvent
+ Control.Monad.Component.Internal.Core: buildComponent :: Text -> IO a -> (a -> IO ()) -> ComponentM a
+ Control.Monad.Component.Internal.Core: buildComponent_ :: Text -> IO a -> ComponentM a
+ Control.Monad.Component.Internal.Core: runComponentM :: Text -> ComponentM a -> (a -> IO b) -> IO b
+ Control.Monad.Component.Internal.Core: runComponentM1 :: (ComponentEvent -> IO ()) -> Text -> ComponentM a -> (a -> IO b) -> IO b
+ Control.Monad.Component.Internal.Types: Build :: !Description -> !Teardown -> !NominalDiffTime -> !(Maybe SomeException) -> !(Set Description) -> Build
+ Control.Monad.Component.Internal.Types: BuildResult :: [Build] -> BuildResult
+ Control.Monad.Component.Internal.Types: ComponentAllocationFailed :: !Description -> !SomeException -> ComponentBuildError
+ Control.Monad.Component.Internal.Types: ComponentBuildFailed :: ![ComponentBuildError] -> !TeardownResult -> ComponentError
+ Control.Monad.Component.Internal.Types: ComponentBuilt :: !BuildResult -> ComponentEvent
+ Control.Monad.Component.Internal.Types: ComponentErrorDetected :: !ComponentError -> ComponentEvent
+ Control.Monad.Component.Internal.Types: ComponentErrorThrown :: !SomeException -> ComponentBuildError
+ Control.Monad.Component.Internal.Types: ComponentIOLiftFailed :: !SomeException -> ComponentBuildError
+ Control.Monad.Component.Internal.Types: ComponentM :: (IO (Either ([ComponentBuildError], BuildTable) (a, BuildTable))) -> ComponentM a
+ Control.Monad.Component.Internal.Types: ComponentReleased :: !TeardownResult -> ComponentEvent
+ Control.Monad.Component.Internal.Types: ComponentRuntimeFailed :: !SomeException -> !TeardownResult -> ComponentError
+ Control.Monad.Component.Internal.Types: DuplicatedComponentKeyDetected :: !Description -> ComponentBuildError
+ Control.Monad.Component.Internal.Types: [buildDependencies] :: Build -> !(Set Description)
+ Control.Monad.Component.Internal.Types: [buildElapsedTime] :: Build -> !NominalDiffTime
+ Control.Monad.Component.Internal.Types: [buildFailure] :: Build -> !(Maybe SomeException)
+ Control.Monad.Component.Internal.Types: [componentDesc] :: Build -> !Description
+ Control.Monad.Component.Internal.Types: [componentErrorBuildErrors] :: ComponentError -> ![ComponentBuildError]
+ Control.Monad.Component.Internal.Types: [componentErrorOriginalException] :: ComponentError -> !SomeException
+ Control.Monad.Component.Internal.Types: [componentErrorTeardownResult] :: ComponentError -> !TeardownResult
+ Control.Monad.Component.Internal.Types: [componentTeardown] :: Build -> !Teardown
+ Control.Monad.Component.Internal.Types: [toBuildList] :: BuildResult -> [Build]
+ Control.Monad.Component.Internal.Types: buildTableToOrderedList :: BuildTable -> [Build]
+ Control.Monad.Component.Internal.Types: buildTableToTeardown :: Text -> BuildTable -> IO Teardown
+ Control.Monad.Component.Internal.Types: data Build
+ Control.Monad.Component.Internal.Types: data ComponentBuildError
+ Control.Monad.Component.Internal.Types: data ComponentError
+ Control.Monad.Component.Internal.Types: data ComponentEvent
+ Control.Monad.Component.Internal.Types: data TeardownResult :: *
+ Control.Monad.Component.Internal.Types: instance Control.Monad.Catch.MonadThrow Control.Monad.Component.Internal.Types.ComponentM
+ Control.Monad.Component.Internal.Types: instance Control.Monad.IO.Class.MonadIO Control.Monad.Component.Internal.Types.ComponentM
+ Control.Monad.Component.Internal.Types: instance Data.Text.Prettyprint.Doc.Internal.Pretty Control.Monad.Component.Internal.Types.Build
+ Control.Monad.Component.Internal.Types: instance Data.Text.Prettyprint.Doc.Internal.Pretty Control.Monad.Component.Internal.Types.BuildResult
+ Control.Monad.Component.Internal.Types: instance Data.Text.Prettyprint.Doc.Internal.Pretty Control.Monad.Component.Internal.Types.ComponentBuildError
+ Control.Monad.Component.Internal.Types: instance Data.Text.Prettyprint.Doc.Internal.Pretty Control.Monad.Component.Internal.Types.ComponentError
+ Control.Monad.Component.Internal.Types: instance Data.Text.Prettyprint.Doc.Internal.Pretty Control.Monad.Component.Internal.Types.ComponentEvent
+ Control.Monad.Component.Internal.Types: instance GHC.Base.Applicative Control.Monad.Component.Internal.Types.ComponentM
+ Control.Monad.Component.Internal.Types: instance GHC.Base.Functor Control.Monad.Component.Internal.Types.ComponentM
+ Control.Monad.Component.Internal.Types: instance GHC.Base.Monad Control.Monad.Component.Internal.Types.ComponentM
+ Control.Monad.Component.Internal.Types: instance GHC.Exception.Exception Control.Monad.Component.Internal.Types.ComponentBuildError
+ Control.Monad.Component.Internal.Types: instance GHC.Exception.Exception Control.Monad.Component.Internal.Types.ComponentError
+ Control.Monad.Component.Internal.Types: instance GHC.Generics.Generic Control.Monad.Component.Internal.Types.Build
+ Control.Monad.Component.Internal.Types: instance GHC.Generics.Generic Control.Monad.Component.Internal.Types.ComponentBuildError
+ Control.Monad.Component.Internal.Types: instance GHC.Generics.Generic Control.Monad.Component.Internal.Types.ComponentError
+ Control.Monad.Component.Internal.Types: instance GHC.Show.Show Control.Monad.Component.Internal.Types.ComponentBuildError
+ Control.Monad.Component.Internal.Types: instance GHC.Show.Show Control.Monad.Component.Internal.Types.ComponentError
+ Control.Monad.Component.Internal.Types: instance RIO.Prelude.Display.Display Control.Monad.Component.Internal.Types.Build
+ Control.Monad.Component.Internal.Types: instance RIO.Prelude.Display.Display Control.Monad.Component.Internal.Types.BuildResult
+ Control.Monad.Component.Internal.Types: instance RIO.Prelude.Display.Display Control.Monad.Component.Internal.Types.ComponentEvent
+ Control.Monad.Component.Internal.Types: newtype BuildResult
+ Control.Monad.Component.Internal.Types: newtype ComponentM a
Files
- CHANGELOG.md +6/−0
- README.md +1/−1
- componentm.cabal +7/−7
- src/Control/Monad/Component.hs +0/−2
- src/Control/Monad/Component/Internal/Types.hs +75/−4
CHANGELOG.md view
@@ -7,6 +7,12 @@ [1]: http://semver.org/spec/v2.0.0.html [2]: https://github.com/roman/Haskell-teardown/libraries/teardown/CHANGELOG.md +## v0.0.0.2++* Add `pretty-show` dependency+* Improve upon pretty instances of types from this library+* Expose internal modules for flexibility+ ## v0.0.0.1 * Relax lower version bounds for `prettyprinter`, `containers`, `exceptions`,
README.md view
@@ -60,7 +60,7 @@ ## Development [](https://travis-ci.org/roman/Haskell-componentm) [](http://packdeps.haskellers.com/feed?needle=componentm)-[](https://img.shields.io/github/commits-since/roman/haskell-componentm/v0.0.0.1.svg)+[](https://img.shields.io/github/commits-since/roman/haskell-componentm/v0.0.0.2.svg) This library is intended to be minimal, providing a few functions that work reliably among many different kind of projects. If you want to contribute, Pull
componentm.cabal view
@@ -1,9 +1,9 @@ cabal-version: >=1.10 name: componentm-version: 0.0.0.1+version: 0.0.0.2 license: MIT license-file: LICENSE-copyright: © 2017-2018 Roman Gonzalez+copyright: © 2017-current Roman Gonzalez maintainer: open-source@roman-gonzalez.info author: Roman Gonzalez stability: alpha (experimental)@@ -17,9 +17,6 @@ It then provides a Monadic interface to compose multiple resources without having to deal with cleanup operations explicitely.- .- Check Control.Monad.Component.Tutorial for an example and- more information. category: System build-type: Simple extra-source-files:@@ -33,10 +30,11 @@ library exposed-modules: Control.Monad.Component- hs-source-dirs: src- other-modules: Control.Monad.Component.Internal.Types Control.Monad.Component.Internal.Core+ hs-source-dirs: src+ other-modules:+ Paths_componentm default-language: Haskell2010 ghc-options: -Wall -Wincomplete-uni-patterns -Wincomplete-record-updates@@ -45,6 +43,7 @@ containers >=0.5.7, deepseq >=1.4.2, exceptions >=0.8.3,+ pretty-show >=1.6.13, prettyprinter >=1.1, rio >=0.0.3, teardown >=0.3@@ -63,6 +62,7 @@ base >=4.8 && <5, componentm -any, containers >=0.5.7,+ pretty-show >=1.6.13, prettyprinter >=1.1, rio >=0.0.3, tasty >=0.11.2,
src/Control/Monad/Component.hs view
@@ -59,12 +59,10 @@ , runComponentM , runComponentM1 - -- * Error Records -- $errors , ComponentError (..) , ComponentBuildError (..)- -- * 'ComponentM' tracing accessors , ComponentEvent (..)
src/Control/Monad/Component/Internal/Types.hs view
@@ -29,6 +29,8 @@ import Control.Teardown (Teardown, TeardownResult, newTeardown) +import Text.Show.Pretty (ppShow)+ -------------------------------------------------------------------------------- -- | Exception thrown by the 'runComponentM' family of functions@@ -55,6 +57,30 @@ instance Exception ComponentError +instance Pretty ComponentError where+ pretty err =+ case err of+ ComponentBuildFailed errList teardownResult ->+ "Application failed on initialization, following are the exceptions that made it failed:"+ <> Pretty.hardline+ <> Pretty.hardline+ <> Pretty.indent 2 (Pretty.vsep $ map (\buildErr -> "* " <> pretty buildErr <> Pretty.hardline) errList)+ <> Pretty.hardline+ <> "Following, we have the information of application resources cleanup:"+ <> Pretty.hardline+ <> Pretty.hardline+ <> pretty teardownResult++ ComponentRuntimeFailed runtimeErr teardownResult ->+ "Application failed at runtime, following is the exception that made the app failed:"+ <> Pretty.hardline+ <> Pretty.hardline+ <> Pretty.indent 2 (pretty $ ppShow runtimeErr)+ <> Pretty.hardline+ <> "Following, we have the information of application resources cleanup:"+ <> Pretty.hardline+ <> pretty teardownResult+ -- | Exception raised on the execution of 'IO' sub-routines used when -- constructing 'ComponentM' values (e.g. 'buildComponent') data ComponentBuildError@@ -70,6 +96,31 @@ instance Exception ComponentBuildError +instance Pretty ComponentBuildError where+ pretty err =+ case err of+ DuplicatedComponentKeyDetected desc ->+ "DuplicateComponentKeyDetected" <+> pretty (show desc) <+> "- please, make sure that component names are unique"++ ComponentAllocationFailed desc componentErr ->+ "ComponentAllocationFailed" <+> pretty (show desc) <+> "- the following error was reported:"+ <> Pretty.nest 2 (Pretty.hardline+ <> "|" <> Pretty.hardline+ <> Pretty.nest 4 ("`-" <+> pretty (ppShow componentErr)))+++ ComponentErrorThrown thrownErr ->+ "ComponentErrorThrown - the following error was thrown using the `throwM` function:"+ <> Pretty.nest 2 (Pretty.hardline+ <> "|" <> Pretty.hardline+ <> Pretty.nest 4 ("`-" <+> pretty (ppShow thrownErr)))++ ComponentIOLiftFailed ioErr ->+ "ComponentIOLiftFailed - the following error was thrown from an `IO` operation invoked via `liftIO`:"+ <> Pretty.nest 2 (Pretty.hardline+ <> "|" <> Pretty.hardline+ <> Pretty.nest 4 ("`-" <+> pretty (ppShow ioErr)))+ type Description = Text -- | Contains metadata about the build of a resource from a 'ComponentM' value@@ -98,7 +149,7 @@ if isJust buildFailure then [ Pretty.hardline- , Pretty.pipe <+> pretty (show buildFailure)+ , Pretty.pipe <+> pretty (ppShow buildFailure) ] else []@@ -123,9 +174,11 @@ instance Pretty BuildResult where pretty (BuildResult builds) =- pretty ("Application Initialized" :: Text)+ "Following, we have the information of the application resources initialization:" <> Pretty.hardline+ <> Pretty.hardline <> Pretty.vsep (map pretty builds)+ <> Pretty.hardline instance Display BuildResult where display buildResult =@@ -136,16 +189,34 @@ data ComponentEvent = ComponentBuilt !BuildResult | ComponentReleased !TeardownResult+ | ComponentErrorDetected !ComponentError instance Pretty ComponentEvent where pretty ev = case ev of ComponentBuilt buildResult ->- pretty buildResult+ Pretty.hardline+ <> "# Application Initialized"+ <> Pretty.hardline+ <> Pretty.hardline+ <> pretty buildResult+ <> Pretty.hardline+ ComponentReleased teardownResult ->- "Application Teardown"+ Pretty.hardline+ <> "# Application Finished" <> Pretty.hardline+ <> Pretty.hardline <> pretty teardownResult+ <> Pretty.hardline++ ComponentErrorDetected err ->+ Pretty.hardline+ <> "# Application Failed"+ <> Pretty.hardline+ <> Pretty.hardline+ <> pretty err+ <> Pretty.hardline instance Display ComponentEvent where display = displayShow . pretty