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.
This commit is contained in:
Simon Michael 2022-07-12 16:11:51 +01:00
parent e6959743f5
commit 84f951e020
5 changed files with 29 additions and 31 deletions

View File

@ -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)

View File

@ -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

View File

@ -1039,7 +1039,7 @@ account1 assets:bank:checking
fields date, description, account2, amount
$ ./csvtest.sh
>2 /unbalanced transaction/
>2 /transaction is unbalanced/
>=1
## .

View File

@ -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.

View File

@ -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.