Build with ghc-9 (#2)

This commit is contained in:
Yuras 2022-04-11 13:48:26 +03:00 committed by GitHub
parent 2cc214d6fd
commit b0c74c0cd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 7 deletions

View File

@ -45,17 +45,18 @@ library
Rollbar.Item.Person
Rollbar.Item.Request
Rollbar.Item.Server
Rollbar.Aeson
other-modules:
Paths_rollbar_hs
hs-source-dirs:
src
build-depends:
aeson >=1.0 && <1.6
aeson >=1.0 && <2.1
, base >=4.9 && <5
, bytestring >=0.10 && <0.11
, case-insensitive >=1.2 && <1.3
, hostname >=1.0 && <1.1
, http-client >=0.5 && <0.7
, http-client >=0.5 && <0.8
, http-conduit >=2.2 && <2.4
, http-types >=0.9 && <0.13
, network >=2.6 && <3.2
@ -83,6 +84,7 @@ test-suite doc-test
, base >=4.9
, bytestring >=0.10
, case-insensitive >=1.2
, hashable
, hspec >=2.4
, hspec-golden-aeson >=0.2
, rollbar-hs

22
src/Rollbar/Aeson.hs Normal file
View File

@ -0,0 +1,22 @@
{-# LANGUAGE CPP #-}
module Rollbar.Aeson
( Key
, textToKey
) where
import Data.Text (Text)
#if MIN_VERSION_aeson(2,0,0)
import Data.Aeson.Key (Key)
import qualified Data.Aeson.Key as Key
#else
#endif
#if MIN_VERSION_aeson(2,0,0)
textToKey :: Text -> Key
textToKey = Key.fromText
#else
type Key = Text
textToKey :: Text -> Key
textToKey = id
#endif

View File

@ -3,6 +3,7 @@
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE CPP #-}
{-|
Module : Rollbar.Item.MissingHeaders
@ -20,6 +21,7 @@ module Rollbar.Item.MissingHeaders
import Data.Aeson
(FromJSON, KeyValue, ToJSON, object, parseJSON, toJSON, (.=))
import Rollbar.Aeson
import Data.Bifunctor (bimap)
import Data.CaseInsensitive (mk, original)
import Data.Maybe (catMaybes)
@ -31,7 +33,6 @@ import Network.HTTP.Types (Header, RequestHeaders)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BSC8
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
-- | The request headers with some missing
@ -72,5 +73,5 @@ requestHeadersKVs = fmap go
val <- myDecodeUtf8 val'
pure (key .= val)
myDecodeUtf8 :: BS.ByteString -> Maybe T.Text
myDecodeUtf8 = either (const Nothing) Just . TE.decodeUtf8'
myDecodeUtf8 :: BS.ByteString -> Maybe Key
myDecodeUtf8 = either (const Nothing) (Just . textToKey) . TE.decodeUtf8'

View File

@ -48,6 +48,7 @@ import GHC.Generics (Generic)
import Network.HTTP.Types (Query)
import Network.Socket (SockAddr(SockAddrInet), tupleToHostAddress)
import Rollbar.Aeson
import Rollbar.Item.MissingHeaders
import Text.Read (readMaybe)
@ -103,7 +104,7 @@ queryKVs = fmap go
go (key', val') = do
key <- myDecodeUtf8 key'
let val = val' >>= myDecodeUtf8
pure (key .= val)
pure (textToKey key .= val)
-- | The HTTP Verb
newtype Method

View File

@ -39,6 +39,6 @@ requiredBodyKeys = ["trace", "trace_chain", "message", "crash_report"]
key :: Text -> Value -> [(Text, Value)]
key k = \case
Object o -> case Data.HashMap.Strict.lookupDefault Null k o of
Object o -> Data.HashMap.Strict.toList o
Object o' -> Data.HashMap.Strict.toList o'
_ -> mempty
_ -> mempty

View File

@ -9,6 +9,7 @@ module Rollbar.Item.MissingHeaders.Test where
import Data.Aeson (Value (Object), decode', encode,
toJSON)
import Data.Functor (void)
import Data.Hashable
import Data.HashSet (HashSet)
import Data.Text (Text)
@ -91,4 +92,5 @@ keys = \case
Object o -> Data.HashSet.fromMap (void o)
_ -> mempty
notMember :: (Eq a, Hashable a) => a -> HashSet a -> Bool
notMember x = not . Data.HashSet.member x