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 where
rmsg rmsg
| rsumok = "" | rsumok = ""
| not rsignsok = "real postings all have the same sign" | not rsignsok = "The real postings all have the same sign."
| otherwise = "real postings' sum should be 0 but is: " ++ showMixedAmountOneLine rsumcost | otherwise = "The real postings' sum should be 0 but is: " ++ showMixedAmountOneLine rsumcost
bvmsg bvmsg
| bvsumok = "" | bvsumok = ""
| not bvsignsok = "balanced virtual postings all have the same sign" | not bvsignsok = "The balanced virtual postings all have the same sign."
| otherwise = "balanced virtual postings' sum should be 0 but is: " ++ showMixedAmountOneLine bvsumcost | otherwise = "The balanced virtual postings' sum should be 0 but is: " ++ showMixedAmountOneLine bvsumcost
-- | Legacy form of transactionCheckBalanced. -- | Legacy form of transactionCheckBalanced.
isTransactionBalanced :: BalancingOpts -> Transaction -> Bool isTransactionBalanced :: BalancingOpts -> Transaction -> Bool
@ -160,7 +160,7 @@ balanceTransactionHelper bopts t = do
errs -> Left $ transactionBalanceError t' errs' errs -> Left $ transactionBalanceError t' errs'
where where
errs' = errs ++ errs' = errs ++
[ "inference of conversion costs has been disallowed" [ "Inference of conversion costs has been disallowed."
| ismulticommodity && not (infer_transaction_prices_ bopts) | ismulticommodity && not (infer_transaction_prices_ bopts)
] ]
where where
@ -169,13 +169,10 @@ balanceTransactionHelper bopts t = do
-- | Generate a transaction balancing error message, given the transaction -- | Generate a transaction balancing error message, given the transaction
-- and one or more suberror messages. -- and one or more suberror messages.
transactionBalanceError :: Transaction -> [String] -> String transactionBalanceError :: Transaction -> [String] -> String
transactionBalanceError t errs = printf (unlines transactionBalanceError t errs = printf "%s:\n%s\n\n%s\n%s"
[ "unbalanced transaction: %s:",
"%s",
"\n%s"
])
(sourcePosPairPretty $ tsourcepos t) (sourcePosPairPretty $ tsourcepos t)
(textChomp ex) (textChomp ex)
("This transaction is unbalanced."::String)
(chomp $ unlines errs) (chomp $ unlines errs)
where where
(_f,_l,_mcols,ex) = makeTransactionErrorExcerpt t finderrcols (_f,_l,_mcols,ex) = makeTransactionErrorExcerpt t finderrcols
@ -200,12 +197,12 @@ inferBalancingAmount ::
inferBalancingAmount styles t@Transaction{tpostings=ps} inferBalancingAmount styles t@Transaction{tpostings=ps}
| length amountlessrealps > 1 | length amountlessrealps > 1
= Left $ transactionBalanceError t = Left $ transactionBalanceError t
["can't have more than one real posting with no amount" ["There can't be more than one real posting with no amount."
,"(remember to put two or more spaces between account and amount)"] ,"(Remember to put two or more spaces between account and amount.)"]
| length amountlessbvps > 1 | length amountlessbvps > 1
= Left $ transactionBalanceError t = Left $ transactionBalanceError t
["can't have more than one balanced virtual posting with no 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)"] ,"(Remember to put two or more spaces between account and amount.)"]
| otherwise | otherwise
= let psandinferredamts = map inferamount ps = let psandinferredamts = map inferamount ps
inferredacctsandamts = [(paccount p, amt) | (p, Just amt) <- psandinferredamts] inferredacctsandamts = [(paccount p, amt) | (p, Just amt) <- psandinferredamts]
@ -584,16 +581,17 @@ checkBalanceAssertionOneCommodityB p@Posting{paccount=assertedacct} assertedamt
aquantity aquantity
-- traceWith (("actual:"++).showAmountDebug) -- traceWith (("actual:"++).showAmountDebug)
actualbalincomm actualbalincomm
errmsg = printf (unlines errmsg = chomp $ printf (unlines
[ "balance assertion: %s:", [ "%s:",
"%s\n", "%s\n",
"This balance assertion failed.",
-- "date: %s", -- "date: %s",
"account: %-30s%s", "In account: %-30s%s",
"commodity: %-30s%s", "and commodity: %-30s%s",
-- "display precision: %d", -- "display precision: %d",
"asserted: %s", -- (at display precision: %s)", "this balance was asserted: %s", -- (at display precision: %s)",
"actual: %s", -- (at display precision: %s)", "but the actual balance is: %s", -- (at display precision: %s)",
"difference: %s" "a difference of: %s"
]) ])
(sourcePosPretty pos) (sourcePosPretty pos)
(textChomp ex) (textChomp ex)

View File

@ -4,5 +4,5 @@
a -10£ a -10£
b 16$ b 16$
$ hledger -f - check balancednoautoconversion $ 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 >=1

View File

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

View File

@ -56,7 +56,7 @@ $ hledger -f - stats
b $-1 = $-3 b $-1 = $-3
$ hledger -f - stats $ hledger -f - stats
>2 /balance assertion.*11:12/ >2 /Error: -:11:12/
>=1 >=1
# 4. should also work without commodity symbols # 4. should also work without commodity symbols
@ -314,7 +314,7 @@ $ hledger -f - stats
a 0 == $1 a 0 == $1
$ hledger -f - stats $ hledger -f - stats
>2 /balance assertion.*10:15/ >2 /Error: -:10:15:/
>=1 >=1
# 18. Mix different commodities and total assignments # 18. Mix different commodities and total assignments
@ -385,7 +385,7 @@ commodity $1000.00
(a) $1.00 = $1.01 (a) $1.00 = $1.01
$ hledger -f- print $ hledger -f- print
>2 /difference: 0\.004/ >2 /a difference of.*0\.004/
>=1 >=1
# 23. This fails # 23. This fails
@ -399,7 +399,7 @@ commodity $1000.00
(a) $1.00 = $1.0061 (a) $1.00 = $1.0061
$ hledger -f- print $ hledger -f- print
>2 /difference: 0\.0001/ >2 /a difference of.*0\.0001/
>=1 >=1
# 24. Inclusive assertions include balances from subaccounts. # 24. Inclusive assertions include balances from subaccounts.

View File

@ -56,7 +56,7 @@ $ hledger -f - print -x
c c
$ hledger -f journal:- print $ 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 >=1
# 6. Two (or more) virtual postings with implicit amount cannot be balanced. # 6. Two (or more) virtual postings with implicit amount cannot be balanced.
@ -123,13 +123,13 @@ $ hledger -f- print
b 1B b 1B
$ hledger -f- print $ hledger -f- print
>2 >2
hledger: Error: unbalanced transaction: -:1-3: hledger: Error: -:1-3:
1 | 2020-01-01 1 | 2020-01-01
| a 1A | a 1A
| b 1B | b 1B
real postings all have the same sign This transaction is unbalanced.
The real postings all have the same sign.
>=1 >=1
# 12. Typical "hledger equity --close" transaction does not trigger sign error. # 12. Typical "hledger equity --close" transaction does not trigger sign error.