From 84f951e020bf870af4e573f192ec4296f033f701 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 12 Jul 2022 16:11:51 +0100 Subject: [PATCH] imp: errors: assertions, balanced: more consistent format Move the unique text out of the first line and down to the explanation. Also, begin some general punctuation, capitalisation and wording improvements. --- hledger-lib/Hledger/Data/Balancing.hs | 40 +++++++++---------- .../test/check-balancednoautoconversion.test | 2 +- hledger/test/csv.test | 2 +- hledger/test/journal/balance-assertions.test | 8 ++-- hledger/test/journal/parse-errors.test | 8 ++-- 5 files changed, 29 insertions(+), 31 deletions(-) diff --git a/hledger-lib/Hledger/Data/Balancing.hs b/hledger-lib/Hledger/Data/Balancing.hs index 351f997d3..309954c58 100644 --- a/hledger-lib/Hledger/Data/Balancing.hs +++ b/hledger-lib/Hledger/Data/Balancing.hs @@ -115,12 +115,12 @@ transactionCheckBalanced BalancingOpts{commodity_styles_} t = errs where rmsg | rsumok = "" - | not rsignsok = "real postings all have the same sign" - | otherwise = "real postings' sum should be 0 but is: " ++ showMixedAmountOneLine rsumcost + | not rsignsok = "The real postings all have the same sign." + | otherwise = "The real postings' sum should be 0 but is: " ++ showMixedAmountOneLine rsumcost bvmsg | bvsumok = "" - | not bvsignsok = "balanced virtual postings all have the same sign" - | otherwise = "balanced virtual postings' sum should be 0 but is: " ++ showMixedAmountOneLine bvsumcost + | not bvsignsok = "The balanced virtual postings all have the same sign." + | otherwise = "The balanced virtual postings' sum should be 0 but is: " ++ showMixedAmountOneLine bvsumcost -- | Legacy form of transactionCheckBalanced. isTransactionBalanced :: BalancingOpts -> Transaction -> Bool @@ -160,7 +160,7 @@ balanceTransactionHelper bopts t = do errs -> Left $ transactionBalanceError t' errs' where errs' = errs ++ - [ "inference of conversion costs has been disallowed" + [ "Inference of conversion costs has been disallowed." | ismulticommodity && not (infer_transaction_prices_ bopts) ] where @@ -169,13 +169,10 @@ balanceTransactionHelper bopts t = do -- | Generate a transaction balancing error message, given the transaction -- and one or more suberror messages. transactionBalanceError :: Transaction -> [String] -> String -transactionBalanceError t errs = printf (unlines - [ "unbalanced transaction: %s:", - "%s", - "\n%s" - ]) +transactionBalanceError t errs = printf "%s:\n%s\n\n%s\n%s" (sourcePosPairPretty $ tsourcepos t) (textChomp ex) + ("This transaction is unbalanced."::String) (chomp $ unlines errs) where (_f,_l,_mcols,ex) = makeTransactionErrorExcerpt t finderrcols @@ -200,12 +197,12 @@ inferBalancingAmount :: inferBalancingAmount styles t@Transaction{tpostings=ps} | length amountlessrealps > 1 = Left $ transactionBalanceError t - ["can't have more than one real posting with no amount" - ,"(remember to put two or more spaces between account and amount)"] + ["There can't be more than one real posting with no amount." + ,"(Remember to put two or more spaces between account and amount.)"] | length amountlessbvps > 1 = Left $ transactionBalanceError t - ["can't have more than one balanced virtual posting with no amount" - ,"(remember to put two or more spaces between account and amount)"] + ["There can't be more than one balanced virtual posting with no amount." + ,"(Remember to put two or more spaces between account and amount.)"] | otherwise = let psandinferredamts = map inferamount ps inferredacctsandamts = [(paccount p, amt) | (p, Just amt) <- psandinferredamts] @@ -584,16 +581,17 @@ checkBalanceAssertionOneCommodityB p@Posting{paccount=assertedacct} assertedamt aquantity -- traceWith (("actual:"++).showAmountDebug) actualbalincomm - errmsg = printf (unlines - [ "balance assertion: %s:", + errmsg = chomp $ printf (unlines + [ "%s:", "%s\n", + "This balance assertion failed.", -- "date: %s", - "account: %-30s%s", - "commodity: %-30s%s", + "In account: %-30s%s", + "and commodity: %-30s%s", -- "display precision: %d", - "asserted: %s", -- (at display precision: %s)", - "actual: %s", -- (at display precision: %s)", - "difference: %s" + "this balance was asserted: %s", -- (at display precision: %s)", + "but the actual balance is: %s", -- (at display precision: %s)", + "a difference of: %s" ]) (sourcePosPretty pos) (textChomp ex) diff --git a/hledger/test/check-balancednoautoconversion.test b/hledger/test/check-balancednoautoconversion.test index 780b8f80e..387cbbc91 100644 --- a/hledger/test/check-balancednoautoconversion.test +++ b/hledger/test/check-balancednoautoconversion.test @@ -4,5 +4,5 @@ a -10£ b 16$ $ hledger -f - check balancednoautoconversion ->2 /real postings' sum should be 0 but is: 16\$/ +>2 /real postings' sum should be 0 but is: 16\$, -10£/ >=1 diff --git a/hledger/test/csv.test b/hledger/test/csv.test index 05f688c44..0039e5e65 100644 --- a/hledger/test/csv.test +++ b/hledger/test/csv.test @@ -1039,7 +1039,7 @@ account1 assets:bank:checking fields date, description, account2, amount $ ./csvtest.sh ->2 /unbalanced transaction/ +>2 /transaction is unbalanced/ >=1 ## . diff --git a/hledger/test/journal/balance-assertions.test b/hledger/test/journal/balance-assertions.test index 1db0dfbd9..e83eb5e9f 100755 --- a/hledger/test/journal/balance-assertions.test +++ b/hledger/test/journal/balance-assertions.test @@ -56,7 +56,7 @@ $ hledger -f - stats b $-1 = $-3 $ hledger -f - stats ->2 /balance assertion.*11:12/ +>2 /Error: -:11:12/ >=1 # 4. should also work without commodity symbols @@ -314,7 +314,7 @@ $ hledger -f - stats a 0 == $1 $ hledger -f - stats ->2 /balance assertion.*10:15/ +>2 /Error: -:10:15:/ >=1 # 18. Mix different commodities and total assignments @@ -385,7 +385,7 @@ commodity $1000.00 (a) $1.00 = $1.01 $ hledger -f- print ->2 /difference: 0\.004/ +>2 /a difference of.*0\.004/ >=1 # 23. This fails @@ -399,7 +399,7 @@ commodity $1000.00 (a) $1.00 = $1.0061 $ hledger -f- print ->2 /difference: 0\.0001/ +>2 /a difference of.*0\.0001/ >=1 # 24. Inclusive assertions include balances from subaccounts. diff --git a/hledger/test/journal/parse-errors.test b/hledger/test/journal/parse-errors.test index 47b58101e..71bda8199 100644 --- a/hledger/test/journal/parse-errors.test +++ b/hledger/test/journal/parse-errors.test @@ -56,7 +56,7 @@ $ hledger -f - print -x c $ hledger -f journal:- print ->2 /can't have more than one real posting with no amount/ +>2 /can't be more than one real posting with no amount/ >=1 # 6. Two (or more) virtual postings with implicit amount cannot be balanced. @@ -123,13 +123,13 @@ $ hledger -f- print b 1B $ hledger -f- print >2 -hledger: Error: unbalanced transaction: -:1-3: +hledger: Error: -:1-3: 1 | 2020-01-01 | a 1A | b 1B -real postings all have the same sign - +This transaction is unbalanced. +The real postings all have the same sign. >=1 # 12. Typical "hledger equity --close" transaction does not trigger sign error.