Skip to content

Commit

Permalink
remove use of head in pact-request-api
Browse files Browse the repository at this point in the history
  • Loading branch information
chessai committed Jul 16, 2024
1 parent 77b28c3 commit 8ad5652
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions pact-request-api/Pact/Core/Command/Client.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import qualified Data.Aeson.Types as A
import qualified Data.Aeson.Key as AK
import qualified Data.Aeson.KeyMap as AKM
import Data.List (intercalate)
import Data.Maybe (fromMaybe, mapMaybe)
import Data.Maybe (fromMaybe, mapMaybe, listToMaybe)
import Data.Bifunctor (first)
import Data.Either (partitionEithers)
import System.IO
Expand Down Expand Up @@ -322,12 +322,18 @@ combineSigs fs outputLocal = do
combineSigDatas :: [SigData Text] -> Bool -> IO ByteString
combineSigDatas [] _ = error "Nothing to combine"
combineSigDatas sds outputLocal = do
let hashes = S.fromList $ map _sigDataHash sds
cmds = S.fromList $ mapMaybe _sigDataCmd sds
when (S.size hashes /= 1 || S.size cmds /= 1) $ do
error "SigData files must contain exactly one unique hash and command. Aborting..."
(hsh, cmd) <- do
let hashAndCmd :: Maybe (Hash, Text)
hashAndCmd = (,)
<$> listToMaybe (S.toList $ S.fromList $ map _sigDataHash sds)
<*> listToMaybe (S.toList $ S.fromList $ mapMaybe _sigDataCmd sds)
case hashAndCmd of
Nothing -> do
error "SigData files must contain exactly one unique hash and command. Aborting..."
Just x -> do
pure x
let sigs = foldl1 f $ map _sigDataSigs sds
returnCommandIfDone outputLocal $ SigData (head $ S.toList hashes) sigs (Just $ head $ S.toList cmds)
returnCommandIfDone outputLocal $ SigData hsh sigs (Just cmd)
where
f accum sigs
| length accum /= length sigs = error "Sig lists have different lengths"
Expand Down

0 comments on commit 8ad5652

Please sign in to comment.