diff --git a/src/Vervis/Darcs.hs b/src/Vervis/Darcs.hs index ab37706..3093bbb 100644 --- a/src/Vervis/Darcs.hs +++ b/src/Vervis/Darcs.hs @@ -282,16 +282,15 @@ joinHunks = -- * The hash may or may not be found in the repo. If there's no patch in the -- repo with the given hash, 'Nothing' is returned. readPatch :: FilePath -> Text -> IO (Maybe Patch) -readPatch path hash = do +readPatch path hash = handle $ runExceptT $ do let pih = PatchInfoHash $ fst $ B16.decode $ encodeUtf8 hash - li <- handle =<< readLatestInventory path latestInventoryAllP + li <- ExceptT $ readLatestInventory path latestInventoryAllP mp <- loop pih (liPatches li) (fst <$> liPrevTag li) for mp $ \ (pi, pch) -> do (_pir, hunks) <- - handle =<< readCompressedPatch path pch (P.patch <* A.endOfInput) - let (an, ae) = - either error id $ - A.parseOnly (author <* A.endOfInput) $ piAuthor pi + ExceptT $ readCompressedPatch path pch (P.patch <* A.endOfInput) + (an, ae) <- + ExceptT . pure $ A.parseOnly (author <* A.endOfInput) $ piAuthor pi return Patch { patchWritten = ( Author @@ -307,7 +306,11 @@ readPatch path hash = do map (mkedit . second joinHunks) $ groupHunksByFile hunks } where - handle = either (const $ fail "readPatch failed") pure + handle a = do + r <- a + case r of + Left e -> fail $ "readPatch failed: " ++ e + Right mp -> return mp lookup' pih ps = case F.find (\ (_pi, pih', _pch) -> pih' == pih) ps of Nothing -> Nothing Just (pi, _pih, pch) -> Just (pi, pch) @@ -316,7 +319,7 @@ readPatch path hash = do Nothing -> case mih of Nothing -> return Nothing Just ih -> do - i <- handle =<< readCompressedInventory path ih earlyInventoryAllP + i <- ExceptT $ readCompressedInventory path ih earlyInventoryAllP case i of Left ei -> loop pih (eiPatches ei) Nothing Right mi -> loop pih (miPatches mi) (Just $ miPrevious mi)