ENH don't stop if a file is not found (or other IO nonsense)

This commit is contained in:
Nathan Dwarshuis 2023-01-28 21:13:16 -05:00
parent 32bbe6e16c
commit ba19b7e92b
3 changed files with 12 additions and 5 deletions

View File

@ -299,13 +299,17 @@ insertManual
insertImport :: MonadUnliftIO m => Import -> MappingT m [InsertError]
insertImport i = whenHash CTImport i [] $ \c -> do
bounds <- asks kmStatementInterval
res <- readImport i
-- TODO this isn't efficient, the whole file will be read and maybe no
-- transactions will be desired
unlessLefts res $ \bs -> do
rs <- mapM resolveTx $ filter (inMaybeBounds bounds . txDate) bs
lift $ mapM_ (insertTx c) rs
res <- tryIO $ readImport i
case res of
Right r -> unlessLefts r $ \bs -> do
bounds <- asks kmStatementInterval
rs <- mapM resolveTx $ filter (inMaybeBounds bounds . txDate) bs
lift $ mapM_ (insertTx c) rs
-- If file is not found (or something else happens) then collect the
-- error try the remaining imports
Left e -> return [InsertIOError $ showT e]
--------------------------------------------------------------------------------
-- low-level transaction stuff

View File

@ -541,6 +541,7 @@ data AllocationSuberr
data InsertError
= RegexError T.Text
| MatchValPrecisionError Natural Natural
| InsertIOError T.Text
| ConversionError T.Text
| LookupError LookupSuberr T.Text
| BalanceError BalanceType CurID [RawSplit]

View File

@ -19,6 +19,7 @@ module Internal.Utils
, unlessLefts
, inMaybeBounds
, acntPath2Text
, showT
)
where
@ -280,6 +281,7 @@ showError (StatementError ts ms) = (showTx <$> ts) ++ (showMatch <$> ms)
showError other = (: []) $ case other of
(RegexError re) -> T.append "could not make regex from pattern: " re
(ConversionError x) -> T.append "Could not convert to rational number: " x
(InsertIOError msg) -> T.append "IO Error: " msg
(MatchValPrecisionError d p) ->
T.unwords ["Match denominator", showT d, "must be less than", showT p]
(LookupError t f) ->