From ed456a3f8c4e368c5712592c4ce582a9b812d22b Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 12 Jul 2023 21:57:05 -1000 Subject: [PATCH] imp:check:recentassertions: improve the error message's suggestion The suggested sample balance assertion now uses the same commodity symbol as in the failing posting (the first, if there are more than one). Also the cleared mark has been removed. --- hledger-lib/Hledger/Data/JournalChecks.hs | 11 +++++++++-- hledger/test/errors/recentassertions.j | 2 +- hledger/test/errors/recentassertions.test | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/hledger-lib/Hledger/Data/JournalChecks.hs b/hledger-lib/Hledger/Data/JournalChecks.hs index dabfb27785a..dba78ce7a4b 100644 --- a/hledger-lib/Hledger/Data/JournalChecks.hs +++ b/hledger-lib/Hledger/Data/JournalChecks.hs @@ -33,7 +33,7 @@ import Hledger.Data.JournalChecks.Ordereddates import Hledger.Data.JournalChecks.Uniqueleafnames import Hledger.Data.Posting (isVirtual, postingDate, transactionAllTags) import Hledger.Data.Types -import Hledger.Data.Amount (amountIsZero, amountsRaw, missingamt) +import Hledger.Data.Amount (amountIsZero, amountsRaw, missingamt, amounts) import Hledger.Data.Transaction (transactionPayee, showTransactionLineFirstPart, partitionAndCheckConversionPostings) import Data.Time (Day, diffDays) import Hledger.Utils @@ -239,6 +239,11 @@ findRecentAssertionError today ps = do let lag = diffDays (postingDate firsterrorp) latestassertdate let acct = paccount firsterrorp let (f,l,_mcols,ex) = makePostingAccountErrorExcerpt firsterrorp + let comm = + case map acommodity $ amounts $ pamount firsterrorp of + [] -> "" + (t:_) | T.length t == 1 -> t + (t:_) -> t <> " " Just $ chomp $ printf (unlines [ "%s:%d:", @@ -250,7 +255,7 @@ findRecentAssertionError today ps = do "", "Consider adding a more recent balance assertion for this account. Eg:", "", - "%s *\n %s $0 = $0 ; (adjust asserted amount)" + "%s\n %s %s0 = %s0 ; (adjust asserted amount)" ]) f l @@ -261,6 +266,8 @@ findRecentAssertionError today ps = do (showDate latestassertdate) (show today) acct + comm + comm -- -- | Print the last balance assertion date & status of all accounts with balance assertions. -- printAccountLastAssertions :: Day -> [BalanceAssertionInfo] -> IO () diff --git a/hledger/test/errors/recentassertions.j b/hledger/test/errors/recentassertions.j index c1370e626d2..e4865cabff0 100755 --- a/hledger/test/errors/recentassertions.j +++ b/hledger/test/errors/recentassertions.j @@ -1,5 +1,4 @@ #!/usr/bin/env -S hledger check recentassertions -f -# Postings more than 7 days after latest balance assertion. 2022-01-01 * a 0 = 0 @@ -7,6 +6,7 @@ 2022-01-08 good a 0 +# More than 7 days after latest balance assertion, fails this check. 2022-01-09 bad1 a 0 diff --git a/hledger/test/errors/recentassertions.test b/hledger/test/errors/recentassertions.test index 1723277a188..b837141b8cc 100644 --- a/hledger/test/errors/recentassertions.test +++ b/hledger/test/errors/recentassertions.test @@ -1,3 +1,4 @@ +# 1. The first posting more than 7 days after latest balance assertion causes this check to fail. $ hledger check recentassertions -f recentassertions.j >2 /Error: .*recentassertions.j:11: | 2022-01-09 bad1