From fb7ffd47618da2dd543c68b28ee37b214724d0f2 Mon Sep 17 00:00:00 2001 From: Kristen Kozak Date: Sat, 14 Mar 2026 23:13:10 -0700 Subject: [PATCH] Fix build errors with older versions of dependencies --- src/Network/JsonRpc/Types.hs | 6 +++--- tests/TestSuite.hs | 10 +++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Network/JsonRpc/Types.hs b/src/Network/JsonRpc/Types.hs index e2e7e38..90e5a37 100644 --- a/src/Network/JsonRpc/Types.hs +++ b/src/Network/JsonRpc/Types.hs @@ -20,7 +20,7 @@ module Network.JsonRpc.Types ( RpcResult , rpcErrorWithData) where import Data.Maybe (catMaybes) -import Data.Text (Text) +import Data.Text (Text, append) #if ! MIN_VERSION_aeson(2,0,0) import Data.Text (unpack) #endif @@ -86,14 +86,14 @@ parseArg :: A.FromJSON r => Text -> A.Value -> Either RpcError r parseArg name val = case A.fromJSON val of A.Error msg -> throwError $ argTypeError msg A.Success x -> return x - where argTypeError = rpcErrorWithData (-32602) $ "Wrong type for argument: " <> name + where argTypeError = rpcErrorWithData (-32602) $ "Wrong type for argument: " `append` name paramDefault :: Parameter a -> Either RpcError a paramDefault (Optional _ d) = Right d paramDefault (Required name) = Left $ missingArgError name missingArgError :: Text -> RpcError -missingArgError name = rpcError (-32602) $ "Cannot find required argument: " <> name +missingArgError name = rpcError (-32602) $ "Cannot find required argument: " `append` name paramName :: Parameter a -> Text paramName (Optional n _) = n diff --git a/tests/TestSuite.hs b/tests/TestSuite.hs index 74e9796..34f97d1 100644 --- a/tests/TestSuite.hs +++ b/tests/TestSuite.hs @@ -24,7 +24,7 @@ import qualified Data.HashMap.Strict as H import qualified Data.ByteString.Lazy.Char8 as LB import Control.Monad.Trans (liftIO) import Control.Monad.State (State, runState, lift, modify) -import Control.Monad.Identity (Identity(..), runIdentity) +import Control.Monad.Identity (Identity, runIdentity) import Test.HUnit hiding (State, Test) import Test.Framework (defaultMain, Test) import Test.Framework.Providers.HUnit (testCase) @@ -189,8 +189,12 @@ getTimeMethod = S.toMethod "get_time_seconds" getTestTime () getTestTime = liftIO $ return 100 removeErrMsg :: A.Value -> A.Value -removeErrMsg (A.Object rsp) = A.Object $ runIdentity $ H.alterF (Identity . fmap removeMsg) "error" rsp - where removeMsg (A.Object err) = A.Object $ H.insert "message" "" $ H.delete "data" err +removeErrMsg (A.Object rsp) = A.Object $ + case H.lookup errorKey rsp of + Nothing -> rsp + Just v -> H.insert errorKey (removeMsg v) rsp + where errorKey = "error" + removeMsg (A.Object err) = A.Object $ H.insert "message" "" $ H.delete "data" err removeMsg v = v removeErrMsg (A.Array rsps) = A.Array $ removeErrMsg `V.map` rsps removeErrMsg v = v