aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuchen Pei <hi@ypei.me>2022-05-30 17:39:15 +1000
committerYuchen Pei <hi@ypei.me>2022-05-30 17:39:15 +1000
commit5e9bed488149f36ed7c2a6a0e58cb0e5c90e1d37 (patch)
tree1680b21002532c33e81b9e465890b16157120f44
parent9a75761328faaa8cc7f177646e3168ee0b03eca7 (diff)
adding error handling
- error with one feed does not crash the whole program
-rw-r--r--src/Main.hs7
1 files changed, 6 insertions, 1 deletions
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 \