avoid head
authorJoey Hess <joeyh@joeyh.name>
Thu, 26 Sep 2024 21:52:19 +0000 (17:52 -0400)
committerJoey Hess <joeyh@joeyh.name>
Thu, 26 Sep 2024 21:52:19 +0000 (17:52 -0400)
Recent ghc has a deprecation warning on it.

This is not an improvement though. I know these cannot fail, but I can't
prove it to ghc.

Assistant/WebApp/Pairing.hs
Remote.hs

index 2c4086a5cf7d99f0b100a54056231d90aea3eb4d..26847e11fb0de21236f33bbc7f4a6ffc40b7bf1e 100644 (file)
@@ -35,8 +35,9 @@ newWormholePairingState = newTVarIO M.empty
 addWormholePairingState :: WormholePairingHandle -> WormholePairingState -> IO WormholePairingId
 addWormholePairingState h tv = atomically $ do
        m <- readTVar tv
-       -- use of head is safe because allids is infinite
-       let i = Prelude.head $ filter (`notElem` M.keys m) allids
+       -- safe because allids is infinite
+       let i = fromMaybe (error "internal") $ 
+               headMaybe $ filter (`notElem` M.keys m) allids
        writeTVar tv (M.insert i h m)
        return i
   where
index 0f19d7a880543747f9b2e3d68f56e95832477a5b..cfe771bb123bbfc9476c18fed039b84d0fe832b7 100644 (file)
--- a/Remote.hs
+++ b/Remote.hs
@@ -473,7 +473,8 @@ claimingUrl = claimingUrl' (const True)
 claimingUrl' :: (Remote -> Bool) -> URLString -> Annex Remote
 claimingUrl' remotefilter url = do
        rs <- remoteList
-       let web = Prelude.head $ filter (\r -> uuid r == webUUID) rs
+       let web = fromMaybe (error "internal") $ headMaybe $
+               filter (\r -> uuid r == webUUID) rs
        fromMaybe web <$> firstM checkclaim (filter remotefilter rs)
   where
        checkclaim = maybe (pure False) (`id` url) . claimUrl