diff --git a/hledger-lib/Hledger/Data/Balancing.hs b/hledger-lib/Hledger/Data/Balancing.hs index 5f3c9767c..970466085 100644 --- a/hledger-lib/Hledger/Data/Balancing.hs +++ b/hledger-lib/Hledger/Data/Balancing.hs @@ -20,7 +20,6 @@ module Hledger.Data.Balancing , balanceTransactionHelper -- * journal balancing , journalBalanceTransactions -, journalCheckBalanceAssertions -- * tests , tests_Balancing ) @@ -376,11 +375,6 @@ costInferrerFor t pt = maybe id infercost inferFromAndTo saturatedAdd a b = if maxBound - a < b then maxBound else a + b --- | Check any balance assertions in the journal and return an error message --- if any of them fail (or if the transaction balancing they require fails). -journalCheckBalanceAssertions :: Journal -> Maybe String -journalCheckBalanceAssertions = either Just (const Nothing) . journalBalanceTransactions defbalancingopts - -- "Transaction balancing", including: inferring missing amounts, -- applying balance assignments, checking transaction balancedness, -- checking balance assertions, respecting posting dates. These things diff --git a/hledger-lib/Hledger/Data/JournalChecks.hs b/hledger-lib/Hledger/Data/JournalChecks.hs index 9aa556792..21575c112 100644 --- a/hledger-lib/Hledger/Data/JournalChecks.hs +++ b/hledger-lib/Hledger/Data/JournalChecks.hs @@ -9,6 +9,7 @@ others can be called only via the check command. module Hledger.Data.JournalChecks ( journalCheckAccounts, + journalCheckBalanceAssertions, journalCheckCommodities, journalCheckPayees, journalCheckPairedConversionPostings, @@ -39,6 +40,8 @@ import Data.Time (Day, diffDays) import Hledger.Utils import Data.Ord import Hledger.Data.Dates (showDate) +import Hledger.Data.Balancing (journalBalanceTransactions, defbalancingopts) + -- | Check that all the journal's postings are to accounts with -- account directives, returning an error message otherwise. @@ -60,6 +63,12 @@ journalCheckAccounts j = mapM_ checkacct (journalPostings j) where (f,l,_mcols,ex) = makePostingAccountErrorExcerpt p +-- | Check all balance assertions in the journal and return an error message if any of them fail. +-- (Technically, this also tries to balance the journal and can return balancing failure errors; +-- ensure the journal is already balanced (with journalBalanceTransactions) to avoid this.) +journalCheckBalanceAssertions :: Journal -> Either String () +journalCheckBalanceAssertions = fmap (const ()) . journalBalanceTransactions defbalancingopts + -- | Check that all the commodities used in this journal's postings have been declared -- by commodity directives, returning an error message otherwise. journalCheckCommodities :: Journal -> Either String () diff --git a/hledger-ui/Hledger/UI/ErrorScreen.hs b/hledger-ui/Hledger/UI/ErrorScreen.hs index ee51b213f..a4a24b254 100644 --- a/hledger-ui/Hledger/UI/ErrorScreen.hs +++ b/hledger-ui/Hledger/UI/ErrorScreen.hs @@ -188,8 +188,8 @@ uiCheckBalanceAssertions _d ui@UIState{ajournal=j} | ui^.ignore_assertions = ui | otherwise = case journalCheckBalanceAssertions j of - Nothing -> ui - Just err -> + Right () -> ui + Left err -> case ui of UIState{aScreen=ES sst} -> ui{aScreen=ES sst{_essError=err}} _ -> pushScreen (esNew err) ui