ENH throw exception upon match error
This commit is contained in:
parent
eb79b325eb
commit
7ad754bead
|
@ -1,3 +1,4 @@
|
||||||
|
{-# LANGUAGE LambdaCase #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
module Main (main) where
|
module Main (main) where
|
||||||
|
@ -156,7 +157,11 @@ runDumpAccountKeys c = do
|
||||||
runSync :: MonadUnliftIO m => FilePath -> m ()
|
runSync :: MonadUnliftIO m => FilePath -> m ()
|
||||||
runSync c = do
|
runSync c = do
|
||||||
config <- readConfig c
|
config <- readConfig c
|
||||||
migrate_ (sqlConfig config) $ do
|
catch (sync_ config) $ \case
|
||||||
|
MatchException -> liftIO $ putStrLn "match error"
|
||||||
|
RegexException -> liftIO $ putStrLn "regex error"
|
||||||
|
where
|
||||||
|
sync_ config = migrate_ (sqlConfig config) $ do
|
||||||
s <- getDBState config
|
s <- getDBState config
|
||||||
flip runReaderT (s $ takeDirectory c) $ do
|
flip runReaderT (s $ takeDirectory c) $ do
|
||||||
insertBudget $ budget config
|
insertBudget $ budget config
|
||||||
|
|
|
@ -302,11 +302,14 @@ insertManual
|
||||||
insertImport :: MonadUnliftIO m => Import -> MappingT m ()
|
insertImport :: MonadUnliftIO m => Import -> MappingT m ()
|
||||||
insertImport i = whenHash CTImport i $ \c -> do
|
insertImport i = whenHash CTImport i $ \c -> do
|
||||||
bounds <- asks kmStatementInterval
|
bounds <- asks kmStatementInterval
|
||||||
bs <- readImport i
|
res <- readImport i
|
||||||
-- TODO this isn't efficient, the whole file will be read and maybe no
|
-- TODO this isn't efficient, the whole file will be read and maybe no
|
||||||
-- transactions will be desired
|
-- transactions will be desired
|
||||||
|
case res of
|
||||||
|
StatementPass bs -> do
|
||||||
rs <- mapM resolveTx $ filter (inMaybeBounds bounds . txDate) bs
|
rs <- mapM resolveTx $ filter (inMaybeBounds bounds . txDate) bs
|
||||||
lift $ mapM_ (insertTx c) rs
|
lift $ mapM_ (insertTx c) rs
|
||||||
|
StatementFail _ -> throwIO MatchException
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- low-level transaction stuff
|
-- low-level transaction stuff
|
||||||
|
|
Loading…
Reference in New Issue