aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2023-12-08 07:34:55 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2023-12-08 07:35:33 +0100
commit5c9c7b360e4578f3db487e663587194746d0386b (patch)
tree625f7adf8430bf847e7ef760e9403f480619c2a2
parent19b148277aa5a80bce1c87e33bb857e66698f4eb (diff)
fix: fix `Git.readTextFileOf`
-rw-r--r--app/Comment.hs2
-rw-r--r--app/Exception.hs2
-rw-r--r--app/Git.hs15
3 files changed, 11 insertions, 8 deletions
diff --git a/app/Comment.hs b/app/Comment.hs
index 558778b..5d1c1ef 100644
--- a/app/Comment.hs
+++ b/app/Comment.hs
@@ -59,7 +59,7 @@ getComments commitHash filePath =
. (T.encodeUtf8 . LT.toStrict)
=<< catch
(Git.readTextFileOf commitHash filePath)
- (\(_ :: E.ProcessException) -> pure "")
+ (\(_ :: E.CannotReadFile) -> pure "")
where
language = fromExtension (takeExtension filePath)
diff --git a/app/Exception.hs b/app/Exception.hs
index 41097b3..5428194 100644
--- a/app/Exception.hs
+++ b/app/Exception.hs
@@ -62,7 +62,7 @@ data InvalidIssue = InvalidIssue (P.ParseErrorBundle [D.Node] Void)
instance Exception InvalidIssue
-data CannotReadFile = CannotReadFile
+data CannotReadFile = CannotReadFile FilePath
deriving (Show)
instance Exception CannotReadFile
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)))