diff --git a/lib/Internal/Insert.hs b/lib/Internal/Insert.hs index eeb6c8a..29e6c47 100644 --- a/lib/Internal/Insert.hs +++ b/lib/Internal/Insert.hs @@ -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 diff --git a/lib/Internal/Types.hs b/lib/Internal/Types.hs index a746545..1355994 100644 --- a/lib/Internal/Types.hs +++ b/lib/Internal/Types.hs @@ -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] diff --git a/lib/Internal/Utils.hs b/lib/Internal/Utils.hs index 3873a3f..3b7ee22 100644 --- a/lib/Internal/Utils.hs +++ b/lib/Internal/Utils.hs @@ -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) ->