From 546362889058de55bc32551a613385b2d5166365 Mon Sep 17 00:00:00 2001 From: Fabian Kirchner Date: Sat, 14 Oct 2023 18:56:48 +0200 Subject: encode again when decoding cache failed --- app/History.hs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'app') 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 -- cgit v1.2.3