From 7ad754bead8ff3edc47b324d3723efe71415dfb5 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Tue, 24 Jan 2023 22:15:32 -0500 Subject: [PATCH] ENH throw exception upon match error --- app/Main.hs | 15 ++++++++++----- lib/Internal/Insert.hs | 9 ++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 149458c..fdeeb18 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE LambdaCase #-} {-# LANGUAGE OverloadedStrings #-} module Main (main) where @@ -156,10 +157,14 @@ runDumpAccountKeys c = do runSync :: MonadUnliftIO m => FilePath -> m () runSync c = do config <- readConfig c - migrate_ (sqlConfig config) $ do - s <- getDBState config - flip runReaderT (s $ takeDirectory c) $ do - insertBudget $ budget config - insertStatements config + catch (sync_ config) $ \case + MatchException -> liftIO $ putStrLn "match error" + RegexException -> liftIO $ putStrLn "regex error" + where + sync_ config = migrate_ (sqlConfig config) $ do + s <- getDBState config + flip runReaderT (s $ takeDirectory c) $ do + insertBudget $ budget config + insertStatements config -- showBalances diff --git a/lib/Internal/Insert.hs b/lib/Internal/Insert.hs index f4f73b5..ba0a736 100644 --- a/lib/Internal/Insert.hs +++ b/lib/Internal/Insert.hs @@ -302,11 +302,14 @@ insertManual insertImport :: MonadUnliftIO m => Import -> MappingT m () insertImport i = whenHash CTImport i $ \c -> do bounds <- asks kmStatementInterval - bs <- readImport i + res <- readImport i -- TODO this isn't efficient, the whole file will be read and maybe no -- transactions will be desired - rs <- mapM resolveTx $ filter (inMaybeBounds bounds . txDate) bs - lift $ mapM_ (insertTx c) rs + case res of + StatementPass bs -> do + rs <- mapM resolveTx $ filter (inMaybeBounds bounds . txDate) bs + lift $ mapM_ (insertTx c) rs + StatementFail _ -> throwIO MatchException -------------------------------------------------------------------------------- -- low-level transaction stuff