From 41feee9b371555bfb61525303a8acb65ac26e1c8 Mon Sep 17 00:00:00 2001 From: rnhmjoj Date: Tue, 7 Sep 2021 14:42:15 +0200 Subject: [PATCH] warn about failed actions --- Main.hs | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/Main.hs b/Main.hs index f70e387..51838e8 100644 --- a/Main.hs +++ b/Main.hs @@ -138,23 +138,27 @@ main = do E.exitSuccess run <- runAction <$> loadSettings opts - run "Cookies" deleteCookies - run "QuotaManager" deleteQuotaOrigins - run "IndexedDB" deleteIndexedDB - run "LocalStorage" deleteLocalStorage - run "SessionStorage" deleteSessionStorage + numFailures <- sum <$> mapM (uncurry run) actions + + if numFailures == 0 + then E.exitSuccess + else do + putStrLn ("\nwarning: " <> show numFailures <> " actions have failed") + E.exitWith (E.ExitFailure numFailures) -- | Runs an 'Action' and pretty-prints the results -runAction :: Settings -> Text -> Action Result -> IO () +runAction :: Settings -> Text -> Action Result -> IO Int runAction settings name x = do a <- BE.try $ runExceptT (runReaderT x settings) case a of - Right (Right res) -> printResult res - Right (Left msg) -> printFailed msg - Left (err :: BE.IOException) -> printFailed (T.pack $ BE.displayException err) + Right (Right res) -> printResult res >> return 0 + Right (Left msg) -> printFailed msg >> return 1 + Left (err :: BE.IOException) -> + printFailed (T.pack $ BE.displayException err) >> return 1 where - printFailed msg = T.putStrLn ("- " <> name <> " cleaning failed:\n " <> msg) + printFailed msg = + T.putStrLn ("- " <> name <> " cleaning failed:\n " <> msg) printResult (n, bad) | n > 0 = do T.putStrLn ("- " <> name <> ": " <> verb <> @@ -168,6 +172,16 @@ runAction settings name x = do -- * Cleaning actions +-- | List of actions and their names +actions :: [(Text, Action Result)] +actions = + [ ("Cookies", deleteCookies) + , ("QuotaManager", deleteQuotaOrigins) + , ("IndexedDB", deleteIndexedDB) + , ("LocalStorage", deleteLocalStorage) + , ("SessionStorage", deleteSessionStorage) + ] + -- | Deletes records in the Cookies database deleteCookies :: Action Result deleteCookies = do