From 8b8edc2f73986ece733dc8651b0a2647d2854bcb Mon Sep 17 00:00:00 2001 From: Juan Gabriel Martinez Date: Fri, 28 Feb 2025 12:25:37 +0100 Subject: [PATCH 1/3] fix issue: createItem not serializing Nothings correctly --- rollbar-client/rollbar-client.cabal | 1 + rollbar-client/src/Rollbar/Client/Item.hs | 14 +++++------ rollbar-client/test/Rollbar/ClientSpec.hs | 29 ++++++++++++++++++++++- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/rollbar-client/rollbar-client.cabal b/rollbar-client/rollbar-client.cabal index 791927e..3b6c375 100644 --- a/rollbar-client/rollbar-client.cabal +++ b/rollbar-client/rollbar-client.cabal @@ -99,4 +99,5 @@ test-suite spec , text , unordered-containers , yaml + , bytestring default-language: Haskell2010 diff --git a/rollbar-client/src/Rollbar/Client/Item.hs b/rollbar-client/src/Rollbar/Client/Item.hs index 5f78124..120bcc4 100644 --- a/rollbar-client/src/Rollbar/Client/Item.hs +++ b/rollbar-client/src/Rollbar/Client/Item.hs @@ -97,15 +97,15 @@ instance ToJSON Item where let dataFields = [ "environment" .= itemEnvironment , "body" .= itemBody - , "level" .= itemLevel - , "platform" .= itemPlatform - , "language" .= itemLanguage - , "framework" .= itemFramework - , "request" .= itemRequest - , "server" .= itemServer , "notifier" .= itemNotifier ] ++ catMaybes - [ ("custom" .=) <$> custom + [ ("level" .=) <$> itemLevel + , ("platform" .=) <$> itemPlatform + , ("language" .=) <$> itemLanguage + , ("framework" .=) <$> itemFramework + , ("request" .=) <$> itemRequest + , ("server" .=) <$> itemServer + , ("custom" .=) <$> custom , ("fingerprint" .=) <$> fingerprint , ("title" .=) <$> title , ("uuid" .=) <$> uuid diff --git a/rollbar-client/test/Rollbar/ClientSpec.hs b/rollbar-client/test/Rollbar/ClientSpec.hs index c53a4b9..0744777 100644 --- a/rollbar-client/test/Rollbar/ClientSpec.hs +++ b/rollbar-client/test/Rollbar/ClientSpec.hs @@ -11,10 +11,12 @@ import qualified Data.Aeson.KeyMap as KM import Control.Monad.Reader import Data.Aeson -import Data.Text +import Data.Text as T import Data.Yaml.Config import Rollbar.Client import Test.Hspec +import Data.Text.Encoding +import Data.ByteString as DB data Package = Package { packageName :: Text @@ -143,3 +145,28 @@ spec = do reportDeploy deploy deployId `shouldSatisfy` (> 0) + + describe "ToJSON Item" $ do + context "when serializing to JSON" $ do + let item = Item + { itemEnvironment = Environment "test" + , itemBody = Body { bodyPayload = PayloadMessage (Message "Test" mempty) } + , itemLevel = Just LevelInfo + , itemPlatform = Just "haskell" + , itemLanguage = Just "Haskell" + , itemFramework = Just "GHC" + , itemRequest = Nothing + , itemServer = Nothing + , custom = Just mempty + , title = Nothing + , uuid = Just "12345" + , fingerprint = Nothing + , itemNotifier = Notifier "rollbar-client" "1.1.0" + } + jsonItem = decodeUtf8 $ toStrict $ encode item + + it "omits fields if they are Nothing values" $ + T.unpack jsonItem `shouldNotContain` "\"server\"" + + it "includes fields if they are Just values" $ + T.unpack jsonItem `shouldContain` "\"platform\":\"haskell\"" \ No newline at end of file From 70407ac0802cff517cd77da741ded7e9f05a4939 Mon Sep 17 00:00:00 2001 From: Juan Gabriel Martinez Date: Fri, 28 Feb 2025 13:33:22 +0100 Subject: [PATCH 2/3] add upper bound to wai-extra to avoid compile issue with yesod --- rollbar-wai/package.yaml | 2 +- rollbar-wai/rollbar-wai.cabal | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/rollbar-wai/package.yaml b/rollbar-wai/package.yaml index d272c54..11c7b66 100644 --- a/rollbar-wai/package.yaml +++ b/rollbar-wai/package.yaml @@ -48,7 +48,7 @@ library: - text >= 1.2 && < 2.1 - unordered-containers >= 0.2 && < 1 - wai >= 3.2 && < 4 - - wai-extra >= 3.0 && < 4 + - "wai-extra < 3.1.17" # TODO: update breaks yesod-core, see https://github.com/yesodweb/yesod/issues/1854 executables: wai-example: diff --git a/rollbar-wai/rollbar-wai.cabal b/rollbar-wai/rollbar-wai.cabal index 2775c08..46f1e82 100644 --- a/rollbar-wai/rollbar-wai.cabal +++ b/rollbar-wai/rollbar-wai.cabal @@ -54,7 +54,8 @@ library , text >=1.2 && <2.1 , unordered-containers >=0.2 && <1 , wai >=3.2 && <4 - , wai-extra >=3.0 && <4 + , wai-extra >=3.0 && < 3.1.17 + -- TODO: update breaks yesod-core, see https://github.com/yesodweb/yesod/issues/1854 default-language: Haskell2010 executable wai-example From 1f31dee5f5e69baa94273a36ba8ce618bc0ec69b Mon Sep 17 00:00:00 2001 From: Juan Gabriel Martinez Date: Fri, 28 Feb 2025 15:15:29 +0100 Subject: [PATCH 3/3] add bytestring to all dependencies --- rollbar-cli/rollbar-cli.cabal | 2 ++ rollbar-client/test/Rollbar/ClientSpec.hs | 4 ++-- rollbar-wai/package.yaml | 2 +- rollbar-wai/rollbar-wai.cabal | 1 + rollbar-yesod/rollbar-yesod.cabal | 2 ++ 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/rollbar-cli/rollbar-cli.cabal b/rollbar-cli/rollbar-cli.cabal index a96327f..ab51dcf 100644 --- a/rollbar-cli/rollbar-cli.cabal +++ b/rollbar-cli/rollbar-cli.cabal @@ -42,6 +42,7 @@ library base >=4.13 && <5 , optparse-applicative >=0.14 && <1 , rollbar-client >=1.0 && <2 + , bytestring >=0.10 && <1 default-language: Haskell2010 executable rollbar @@ -68,4 +69,5 @@ test-suite spec build-depends: base >=4.13 && <5 , rollbar-cli + , bytestring >=0.10 && <1 default-language: Haskell2010 diff --git a/rollbar-client/test/Rollbar/ClientSpec.hs b/rollbar-client/test/Rollbar/ClientSpec.hs index 0744777..3549779 100644 --- a/rollbar-client/test/Rollbar/ClientSpec.hs +++ b/rollbar-client/test/Rollbar/ClientSpec.hs @@ -16,7 +16,7 @@ import Data.Yaml.Config import Rollbar.Client import Test.Hspec import Data.Text.Encoding -import Data.ByteString as DB +import qualified Data.ByteString.Lazy as DBL data Package = Package { packageName :: Text @@ -163,7 +163,7 @@ spec = do , fingerprint = Nothing , itemNotifier = Notifier "rollbar-client" "1.1.0" } - jsonItem = decodeUtf8 $ toStrict $ encode item + jsonItem = decodeUtf8 $ DBL.toStrict $ encode item it "omits fields if they are Nothing values" $ T.unpack jsonItem `shouldNotContain` "\"server\"" diff --git a/rollbar-wai/package.yaml b/rollbar-wai/package.yaml index 11c7b66..efaf38b 100644 --- a/rollbar-wai/package.yaml +++ b/rollbar-wai/package.yaml @@ -48,7 +48,7 @@ library: - text >= 1.2 && < 2.1 - unordered-containers >= 0.2 && < 1 - wai >= 3.2 && < 4 - - "wai-extra < 3.1.17" # TODO: update breaks yesod-core, see https://github.com/yesodweb/yesod/issues/1854 + - wai-extra < 3.1.17 # TODO: update breaks yesod-core, see https://github.com/yesodweb/yesod/issues/1854 executables: wai-example: diff --git a/rollbar-wai/rollbar-wai.cabal b/rollbar-wai/rollbar-wai.cabal index 46f1e82..f50badb 100644 --- a/rollbar-wai/rollbar-wai.cabal +++ b/rollbar-wai/rollbar-wai.cabal @@ -102,4 +102,5 @@ test-suite spec , unordered-containers , wai , warp >=3.3 && <4 + , bytestring default-language: Haskell2010 diff --git a/rollbar-yesod/rollbar-yesod.cabal b/rollbar-yesod/rollbar-yesod.cabal index b1cf522..36cdd4f 100644 --- a/rollbar-yesod/rollbar-yesod.cabal +++ b/rollbar-yesod/rollbar-yesod.cabal @@ -51,6 +51,7 @@ library , unliftio >=0.2 && <1 , wai >=3.2 && <4 , yesod-core >=1.6 && <2 + , bytestring >= 0.10 default-language: Haskell2010 executable yesod-example @@ -91,4 +92,5 @@ test-suite spec , wai , yesod-core , yesod-test >=1.6 && <2 + , bytestring >= 0.10 default-language: Haskell2010