aboutsummaryrefslogtreecommitdiffstats
path: root/app/History.hs
diff options
context:
space:
mode:
authorLibravatar Fabian Kirchner <kirchner@posteo.de>2023-10-14 18:56:48 +0200
committerLibravatar Fabian Kirchner <kirchner@posteo.de>2023-10-14 18:56:48 +0200
commit546362889058de55bc32551a613385b2d5166365 (patch)
tree28f9445ddcf1b8f53cb70ef0c47868be6a3f83e0 /app/History.hs
parentc14d4628079b059cd1394598388ab4c5a4cf7650 (diff)
encode again when decoding cache failed
Diffstat (limited to 'app/History.hs')
-rw-r--r--app/History.hs12
1 files changed, 10 insertions, 2 deletions
diff --git a/app/History.hs b/app/History.hs
index b6cef76..a12ea6e 100644
--- a/app/History.hs
+++ b/app/History.hs
@@ -6,7 +6,7 @@ module History (getIssues, listIssues) where
import Control.Exception (Exception, catch, handle, throw)
import Data.Aeson (eitherDecode)
-import Data.Binary (Binary, decodeFile, encodeFile)
+import Data.Binary (Binary, decodeFileOrFail, encodeFile)
import Data.ByteString.Lazy.Char8 qualified as L8
import Data.Function ((&))
import Data.List (foldl', intercalate)
@@ -342,7 +342,15 @@ cached hash func = do
let file = (cwd ++ "/.anissue/" ++ unpack hash)
fileExists <- doesFileExist file
if fileExists
- then decodeFile file
+ then do
+ result <- decodeFileOrFail file
+ case result of
+ Left _ -> do
+ blob <- func hash
+ encodeFile file blob
+ pure blob
+ Right blob ->
+ pure blob
else do
blob <- func hash
encodeFile file blob