warn about failed actions
This commit is contained in:
parent
a0c17c434a
commit
41feee9b37
34
Main.hs
34
Main.hs
@ -138,23 +138,27 @@ main = do
|
|||||||
E.exitSuccess
|
E.exitSuccess
|
||||||
|
|
||||||
run <- runAction <$> loadSettings opts
|
run <- runAction <$> loadSettings opts
|
||||||
run "Cookies" deleteCookies
|
numFailures <- sum <$> mapM (uncurry run) actions
|
||||||
run "QuotaManager" deleteQuotaOrigins
|
|
||||||
run "IndexedDB" deleteIndexedDB
|
if numFailures == 0
|
||||||
run "LocalStorage" deleteLocalStorage
|
then E.exitSuccess
|
||||||
run "SessionStorage" deleteSessionStorage
|
else do
|
||||||
|
putStrLn ("\nwarning: " <> show numFailures <> " actions have failed")
|
||||||
|
E.exitWith (E.ExitFailure numFailures)
|
||||||
|
|
||||||
|
|
||||||
-- | Runs an 'Action' and pretty-prints the results
|
-- | 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
|
runAction settings name x = do
|
||||||
a <- BE.try $ runExceptT (runReaderT x settings)
|
a <- BE.try $ runExceptT (runReaderT x settings)
|
||||||
case a of
|
case a of
|
||||||
Right (Right res) -> printResult res
|
Right (Right res) -> printResult res >> return 0
|
||||||
Right (Left msg) -> printFailed msg
|
Right (Left msg) -> printFailed msg >> return 1
|
||||||
Left (err :: BE.IOException) -> printFailed (T.pack $ BE.displayException err)
|
Left (err :: BE.IOException) ->
|
||||||
|
printFailed (T.pack $ BE.displayException err) >> return 1
|
||||||
where
|
where
|
||||||
printFailed msg = T.putStrLn ("- " <> name <> " cleaning failed:\n " <> msg)
|
printFailed msg =
|
||||||
|
T.putStrLn ("- " <> name <> " cleaning failed:\n " <> msg)
|
||||||
printResult (n, bad)
|
printResult (n, bad)
|
||||||
| n > 0 = do
|
| n > 0 = do
|
||||||
T.putStrLn ("- " <> name <> ": " <> verb <>
|
T.putStrLn ("- " <> name <> ": " <> verb <>
|
||||||
@ -168,6 +172,16 @@ runAction settings name x = do
|
|||||||
|
|
||||||
-- * Cleaning actions
|
-- * 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
|
-- | Deletes records in the Cookies database
|
||||||
deleteCookies :: Action Result
|
deleteCookies :: Action Result
|
||||||
deleteCookies = do
|
deleteCookies = do
|
||||||
|
Loading…
Reference in New Issue
Block a user