From 233a559aafe0561ced97f963922e97cc2f435f9c Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Tue, 10 Sep 2024 20:12:46 -0400 Subject: [PATCH] Don't crash if the database doesn't exist --- src/Password/App/Event.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Password/App/Event.hs b/src/Password/App/Event.hs index 65d2869..b8f7cbc 100644 --- a/src/Password/App/Event.hs +++ b/src/Password/App/Event.hs @@ -47,6 +47,7 @@ import Lens.Micro ((^.)) import Lens.Micro.Mtl (zoom) import System.EasyFile ( createDirectoryIfMissing + , doesFileExist , getAppUserDataDirectory , () ) @@ -70,7 +71,9 @@ loadDatabase = zoom database $ liftIO ( do dir <- mkAppDir let fn = dir dbFile - decodeFileStrict fn + doesFileExist fn >>= \case + True -> decodeFileStrict fn + False -> return Nothing ) >>= mapM_ put fallbackHandler :: BrickEvent ResName () -> EventM ResName AppState ()