From 3138046744fa65a71cb9fcb1c561b9c2230d483c Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 15 Oct 2008 06:47:47 +0000 Subject: [PATCH] clarify entry balance checking and show the full entry when unbalanced --- Ledger/Entry.hs | 11 ++++++----- Ledger/Parse.hs | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Ledger/Entry.hs b/Ledger/Entry.hs index cdbbdc126..426dd4911 100644 --- a/Ledger/Entry.hs +++ b/Ledger/Entry.hs @@ -42,11 +42,12 @@ isEntryBalanced :: Entry -> Bool isEntryBalanced = isZeroAmount . sumLedgerTransactions . etransactions autofillEntry :: Entry -> Entry -autofillEntry e@(Entry _ _ _ _ _ ts _) = - let e' = e{etransactions=autofillTransactions ts} in - case (isEntryBalanced e') of - True -> e' - False -> (error $ "transactions don't balance in " ++ show e) +autofillEntry e@(Entry {etransactions=ts}) = e{etransactions=autofillTransactions ts} + +assertBalancedEntry :: Entry -> Entry +assertBalancedEntry e + | isEntryBalanced e = e + | otherwise = error $ "transactions don't balance in:\n" ++ show e {-| Helper for the print command which shows cleaned up ledger file diff --git a/Ledger/Parse.hs b/Ledger/Parse.hs index 68582015f..f03bc8b56 100644 --- a/Ledger/Parse.hs +++ b/Ledger/Parse.hs @@ -231,7 +231,7 @@ ledgerentry = do comment <- ledgercomment restofline transactions <- ledgertransactions - return $ autofillEntry $ Entry date status code description comment transactions (unlines preceding) + return $ assertBalancedEntry $ autofillEntry $ Entry date status code description comment transactions (unlines preceding) ledgerdate :: Parser String ledgerdate = do