diff --git a/flake.lock b/flake.lock index be181da..be94ed7 100644 --- a/flake.lock +++ b/flake.lock @@ -20,16 +20,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1701263465, - "narHash": "sha256-lNXUIlkfyDyp9Ox21hr+wsEf/IBklLvb6bYcyeXbdRc=", + "lastModified": 1747209494, + "narHash": "sha256-fLise+ys+bpyjuUUkbwqo5W/UyIELvRz9lPBPoB0fbM=", "owner": "nixos", "repo": "nixpkgs", - "rev": "50aa30a13c4ab5e7ba282da460a3e3d44e9d0eb3", + "rev": "5d736263df906c5da72ab0f372427814de2f52f8", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixos-23.11", + "ref": "nixos-24.11", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index c3dd9a5..8bc3730 100644 --- a/flake.nix +++ b/flake.nix @@ -1,10 +1,15 @@ { inputs = { flake-utils.url = "github:numtide/flake-utils"; - nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11"; + nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11"; }; - outputs = { self, flake-utils, nixpkgs }: + outputs = + { + self, + flake-utils, + nixpkgs, + }: flake-utils.lib.simpleFlake { inherit self nixpkgs; name = "rollbar-haskell"; diff --git a/rollbar-wai/ChangeLog.md b/rollbar-wai/ChangeLog.md index 9064ccc..0a00ce0 100644 --- a/rollbar-wai/ChangeLog.md +++ b/rollbar-wai/ChangeLog.md @@ -9,3 +9,8 @@ All notable changes to this project will be documented in this file. - Changed `text` dependency upper bound: we now support `text-2.0.X.X`. ## Unreleased changes + +### Changed +- `rollbarOnExceptionWith` now takes a fork function of type `IO () -> IO ()`. +- All tests are now synchronous and no longer use `threadDelay`. +- Updated `rollbarOnException` and all usages to match the new signature. diff --git a/rollbar-wai/package.yaml b/rollbar-wai/package.yaml index 88d8dec..599a28e 100644 --- a/rollbar-wai/package.yaml +++ b/rollbar-wai/package.yaml @@ -1,5 +1,5 @@ name: rollbar-wai -version: 1.1.1 +version: 1.2.0 github: "stackbuilders/rollbar-haskell" license: MIT author: "Stack Builders Inc." diff --git a/rollbar-wai/rollbar-wai.cabal b/rollbar-wai/rollbar-wai.cabal index 3e7252a..22ee79d 100644 --- a/rollbar-wai/rollbar-wai.cabal +++ b/rollbar-wai/rollbar-wai.cabal @@ -5,7 +5,7 @@ cabal-version: 1.12 -- see: https://github.com/sol/hpack name: rollbar-wai -version: 1.1.1 +version: 1.2.0 synopsis: Provides error reporting capabilities to WAI based applications through Rollbar API. description: Please see the README on GitHub at diff --git a/rollbar-wai/src/Rollbar/Wai.hs b/rollbar-wai/src/Rollbar/Wai.hs index 3cdc224..437c2e3 100644 --- a/rollbar-wai/src/Rollbar/Wai.hs +++ b/rollbar-wai/src/Rollbar/Wai.hs @@ -50,7 +50,7 @@ rollbarOnException -> Maybe W.Request -> SomeException -> m () -rollbarOnException = rollbarOnExceptionWith (void . createItem) +rollbarOnException = rollbarOnExceptionWith (void . forkIO) (void . createItem) -- | Similar to 'rollbarOnExceptionWith', but it allows customize the function -- used to send the 'Item' to Rollbar. @@ -58,13 +58,14 @@ rollbarOnException = rollbarOnExceptionWith (void . createItem) -- @since 0.1.0 rollbarOnExceptionWith :: MonadIO m - => (Item -> Rollbar ()) + => (IO () -> IO ()) -- ^ fork function (returns unit) + -> (Item -> Rollbar ()) -> Settings -> Maybe W.Request -> SomeException -> m () -rollbarOnExceptionWith f settings waiRequest ex = - void $ liftIO $ forkIO $ runRollbar settings $ do +rollbarOnExceptionWith fork f settings waiRequest ex = + void $ liftIO $ fork $ runRollbar settings $ do item <- mkItem $ PayloadTrace $ Trace [] $ mkException ex request <- mapM mkRequest waiRequest f item diff --git a/rollbar-wai/test/Rollbar/WaiSpec.hs b/rollbar-wai/test/Rollbar/WaiSpec.hs index 8dd8edc..df822de 100644 --- a/rollbar-wai/test/Rollbar/WaiSpec.hs +++ b/rollbar-wai/test/Rollbar/WaiSpec.hs @@ -10,7 +10,6 @@ import qualified Data.Text as T import qualified Network.Wai as W import qualified Network.Wai.Handler.Warp as W -import Control.Concurrent (threadDelay) import Control.Monad (join) import Control.Monad.IO.Class import Data.Aeson @@ -33,7 +32,6 @@ spec = before getSettingsAndItemRef $ (req GET url NoReqBody bsResponse $ port warpPort) responseStatusCode response `shouldBe` 200 responseBody response `shouldBe` "OK" - threadDelay 500 readIORef itemRef `shouldReturn` Nothing context "when the response status code is not 200" $ @@ -44,7 +42,6 @@ spec = before getSettingsAndItemRef $ (defaultHttpConfig { httpConfigCheckResponse = \_ _ _ -> Nothing }) (req GET url NoReqBody bsResponse $ port warpPort) response `shouldBe` "Something went wrong" - threadDelay 500 let portAsText = T.pack $ show warpPort join . fmap itemRequest <$> readIORef itemRef `shouldReturn` Just ( Request @@ -75,7 +72,7 @@ withApp -> IO a withApp f (settings, itemRef) = do let waiSettings = W.setOnException - (rollbarOnExceptionWith (createItemFake itemRef) settings) + (rollbarOnExceptionWith id (createItemFake itemRef) settings) W.defaultSettings W.withApplicationSettings waiSettings (return app) $ f itemRef diff --git a/rollbar-yesod/package.yaml b/rollbar-yesod/package.yaml index ff17c88..908cb73 100644 --- a/rollbar-yesod/package.yaml +++ b/rollbar-yesod/package.yaml @@ -1,5 +1,5 @@ name: rollbar-yesod -version: 1.1.1 +version: 1.1.2 github: "stackbuilders/rollbar-haskell" license: MIT author: "Stack Builders Inc." @@ -41,7 +41,7 @@ library: source-dirs: src dependencies: - rollbar-client >= 1.0 && < 2 - - rollbar-wai >= 1.0 && < 2 + - rollbar-wai >= 1.2 && < 2 - unliftio >= 0.2 && < 1 - wai >= 3.2 && < 4 - yesod-core >= 1.6 && < 2 diff --git a/rollbar-yesod/rollbar-yesod.cabal b/rollbar-yesod/rollbar-yesod.cabal index 8649350..275caa0 100644 --- a/rollbar-yesod/rollbar-yesod.cabal +++ b/rollbar-yesod/rollbar-yesod.cabal @@ -5,7 +5,7 @@ cabal-version: 1.12 -- see: https://github.com/sol/hpack name: rollbar-yesod -version: 1.1.1 +version: 1.1.2 synopsis: Provides error reporting capabilities to Yesod applications through Rollbar API. description: Please see the README on GitHub at @@ -45,7 +45,7 @@ library build-depends: base >=4.18 && <5 , rollbar-client >=1.0 && <2 - , rollbar-wai >=1.0 && <2 + , rollbar-wai >=1.2 && <2 , unliftio >=0.2 && <1 , wai >=3.2 && <4 , yesod-core >=1.6 && <2 diff --git a/rollbar-yesod/src/Rollbar/Yesod.hs b/rollbar-yesod/src/Rollbar/Yesod.hs index 24e67ef..9b150ac 100644 --- a/rollbar-yesod/src/Rollbar/Yesod.hs +++ b/rollbar-yesod/src/Rollbar/Yesod.hs @@ -17,6 +17,7 @@ module Rollbar.Yesod import qualified Network.Wai as W +import Control.Concurrent (forkIO) import Control.Exception (Exception(..), SomeException) import Control.Monad (unless, void) import Rollbar.Client @@ -40,7 +41,7 @@ rollbarYesodMiddleware => m a -> m a rollbarYesodMiddleware = rollbarYesodMiddlewareWith $ \settings request ex -> - rollbarOnExceptionWith handler settings (Just request) ex + rollbarOnExceptionWith (void . forkIO) handler settings (Just request) ex where handler item = void $ createItem item { itemFramework = Just "yesod" }