From 5e9bed488149f36ed7c2a6a0e58cb0e5c90e1d37 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 30 May 2022 17:39:15 +1000 Subject: adding error handling - error with one feed does not crash the whole program --- src/Main.hs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Main.hs b/src/Main.hs index ca71b29..e5b33d4 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -26,6 +26,7 @@ import Control.Monad.IO.Class import Control.Monad.Logger import System.Directory import Control.Monad.Extra +import Control.Exception import F2Md.Types import F2Md.Import import F2Md.Export @@ -41,7 +42,11 @@ main = do mapM_ (createDirectoryIfMissing True) [root "new", root "cur", root "tmp"] let dbPath = fromMaybe (oDbPath options) mbDbPath - mapM_ (runStdoutLoggingT . processFeed root dbPath) feeds + mapM_ (\feed -> + catch (runStdoutLoggingT $ processFeed root dbPath feed) + (\e -> runStderrLoggingT $ logErrorN $ + (T.pack $ show (e :: SomeException)) <> "\n")) + feeds where opts = info (progParser <**> helper) (fullDesc <> progDesc "f2md feeds to maildir" <> header "f2md - a utility to pull new items \ -- cgit v1.2.3