1
0
Fork 0
mirror of https://code.sup39.dev/repos/Wqawg synced 2024-12-29 00:34:54 +09:00

When parsing a Darcs repo's patch file, fail with error detail in the message

I'm not sure this will improve much, because the error messages come from
attoparsec, but at least the message text won't be constant, which was the
previous situation.
This commit is contained in:
fr33domlover 2019-10-23 09:31:37 +00:00
parent 90ad05b327
commit bdc48f4ca2

View file

@ -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)