From 5c9c7b360e4578f3db487e663587194746d0386b Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Fri, 8 Dec 2023 07:34:55 +0100 Subject: fix: fix `Git.readTextFileOf` --- app/Git.hs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'app/Git.hs') diff --git a/app/Git.hs b/app/Git.hs index d308026..b4e36e1 100644 --- a/app/Git.hs +++ b/app/Git.hs @@ -12,7 +12,7 @@ module Git ) where -import Control.Exception (throw, throwIO) +import Control.Exception (IOException, catch, throw, throwIO) import Data.Binary (Binary, Put, get, put) import Data.ByteString.Lazy qualified as LB import Data.Fixed (Pico) @@ -30,6 +30,7 @@ import Exception qualified as E import GHC.Generics (Generic) import Git.CommitHash import Process (proc, sh) +import Text.Printf (printf) import Prelude hiding (lines) getCommitHashes :: IO (NonEmpty T.Text) @@ -105,10 +106,12 @@ getCommitOf commitHash@(Commit hash) = do } _ -> throwIO E.NoCommits --- TODO Fix `readTextFileOf` --- --- Handle file does not exist in `WorkingTree` case. readTextFileOf :: CommitHash -> FilePath -> IO LT.Text -readTextFileOf WorkingTree filePath = LT.readFile filePath +readTextFileOf WorkingTree filePath = + catch + (LT.readFile filePath) + (\(_ :: IOException) -> throwIO (E.CannotReadFile filePath)) readTextFileOf (Commit hash) filePath = - LT.decodeUtf8 <$> sh (proc "git show %:%" hash filePath) + catch + (LT.decodeUtf8 <$> sh (proc "git show %:%" hash filePath)) + (\(_ :: E.ProcessException) -> throwIO (E.CannotReadFile (printf "%s:%s" hash filePath))) -- cgit v1.2.3