From ed3565b0280912a8fad66f5b4bb36ca7a632440d Mon Sep 17 00:00:00 2001 From: Emmanuel Denloye-Ito Date: Thu, 1 Feb 2024 19:20:16 -0500 Subject: [PATCH] use ByteString for ElasticSearchExcetion --- exec/TXG.hs | 9 +++++---- lib/TXG/Utils.hs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/exec/TXG.hs b/exec/TXG.hs index 6c4977e..6d3c991 100644 --- a/exec/TXG.hs +++ b/exec/TXG.hs @@ -55,6 +55,7 @@ import qualified Data.Map as M import Data.Maybe import Data.Sequence.NonEmpty (NESeq(..)) import qualified Data.Sequence.NonEmpty as NES +import Data.String (fromString) import Data.String.Conv (toS) import Data.Text (Text) import qualified Data.Text as T @@ -552,7 +553,7 @@ esCheckIndex mgr logger esConf version = do let indexCreated = object ["acknowledged" .= True, "shards_acknowledged" .= True, "index" .= indexName ] if val == indexCreated && (status == 200 || status == 201) then liftIO $ loggerFunIO logger Info $ "Index " <> T.pack indexName <> " created" - else throwM $ ElasticSearchException $ "esCheckIndex: Unexpected response: " <> T.pack (show val) + else throwM $ ElasticSearchException $ "esCheckIndex: Unexpected response:\n" <> (LB.toStrict $ encode val) return $ Right $ IndexExists True createElasticsearchIndex :: MonadIO m => MonadThrow m => ElasticSearchConfig -> Logger Text -> ChainwebVersion -> m HTTP.Request @@ -773,7 +774,7 @@ realTransactions config (ChainwebHost h _p2p service) tcut tv distribution = do logger' <- ask retryResp <- retrying policy toRetry (const $ esCheckIndex (confManager cfg) logger' esConfig (nodeVersion config)) case retryResp of - Left err -> throwM $ ElasticSearchException $ T.pack err + Left err -> throwM $ ElasticSearchException $ fromString err Right (IndexExists exists) -> unless exists $ void $ retrying policy toRetry (const $ esPutReq (confManager cfg) logger' esConfig (nodeVersion config)) let act = loop (confirmationDepth config) tcut (liftIO randomEnum >>= generateTransactions False (verbose config)) @@ -877,7 +878,7 @@ realCoinTransactions config (ChainwebHost h _p2p service) tcut tv distribution = logger' <- ask retryResp <- retrying policy toRetry (const $ esCheckIndex (confManager cfg) logger' esConfig (nodeVersion config)) case retryResp of - Left err -> throwM $ ElasticSearchException $ T.pack err + Left err -> throwM $ ElasticSearchException $ fromString err Right (IndexExists exists) -> unless exists $ void $ retrying policy toRetry (const $ esPutReq (confManager cfg) logger' esConfig (nodeVersion config)) let act = loop (confirmationDepth config) tcut (generateTransactions True (verbose config) CoinContract) @@ -922,7 +923,7 @@ simpleExpressions config (ChainwebHost h _p2p service) tcut tv distribution = do logger' <- ask retryResp <- retrying policy toRetry (const $ esCheckIndex (confManager gencfg) logger' esConfig (nodeVersion config)) case retryResp of - Left err -> throwM $ ElasticSearchException $ T.pack err + Left err -> throwM $ ElasticSearchException $ fromString err Right (IndexExists exists) -> unless exists $ void $ retrying policy toRetry (const $ esPutReq (confManager gencfg) logger' esConfig (nodeVersion config)) let chs = maybe (versionChains $ nodeVersion config) NES.fromList diff --git a/lib/TXG/Utils.hs b/lib/TXG/Utils.hs index 23c44d6..b222d03 100644 --- a/lib/TXG/Utils.hs +++ b/lib/TXG/Utils.hs @@ -203,7 +203,7 @@ unsafeManager :: IO Manager unsafeManager = newTlsManagerWith $ mkManagerSettings (TLSSettingsSimple True True True) Nothing -newtype ElasticSearchException = ElasticSearchException T.Text +newtype ElasticSearchException = ElasticSearchException B.ByteString deriving (Show, Eq, Ord, IsString, Generic) -- -------------------------------------------------------------------------- --