journal: better errors and debug output for balance assertions
With --debug=2, better information about assertions is printed. Balance assertion errors now have a more standard and parseable layout. The asserted balance is now shown with the diff, let's see if that's better.
This commit is contained in:
parent
2d7a1904b4
commit
479a4138fe
@ -500,42 +500,47 @@ checkBalanceAssertionsForAccount ps
|
|||||||
checkBalanceAssertion :: ([String],MixedAmount) -> [Posting] -> ([String],MixedAmount)
|
checkBalanceAssertion :: ([String],MixedAmount) -> [Posting] -> ([String],MixedAmount)
|
||||||
checkBalanceAssertion (errs,startbal) ps
|
checkBalanceAssertion (errs,startbal) ps
|
||||||
| null ps = (errs,startbal)
|
| null ps = (errs,startbal)
|
||||||
| isNothing assertion = (errs,startbal)
|
| isNothing $ pbalanceassertion p = (errs,startbal)
|
||||||
| -- bal' /= assertedbal -- MixedAmount's Eq instance currently gets confused by different precisions
|
| iswrong = (errs++[err], finalfullbal)
|
||||||
not $ isReallyZeroMixedAmount (actualbal - assertedbal) = (errs++[err], finalfullbal)
|
|
||||||
| otherwise = (errs,finalfullbal)
|
| otherwise = (errs,finalfullbal)
|
||||||
where
|
where
|
||||||
p = last ps
|
p = last ps
|
||||||
assertion = pbalanceassertion p
|
Just assertedbal = pbalanceassertion p
|
||||||
Just assertedbal = dbg2 "assertedbal" assertion
|
assertedcomm = maybe "" acommodity $ headMay $ amounts assertedbal
|
||||||
assertedcomm = dbg2 "assertedcomm" $ maybe "" acommodity $ headMay $ amounts assertedbal
|
finalfullbal = sum $ [startbal] ++ map pamount (dbg2 "ps" ps)
|
||||||
finalfullbal = dbg2 "finalfullbal" $ sum $ [dbg2 "startbal" startbal] ++ map pamount ps
|
finalsinglebal = filterMixedAmount (\a -> acommodity a == assertedcomm) finalfullbal
|
||||||
finalsinglebal = dbg2 "finalsinglebal" $ filterMixedAmount (\a -> acommodity a == assertedcomm) finalfullbal
|
|
||||||
actualbal = finalsinglebal -- just check the single-commodity balance, like Ledger; maybe add ==FULLBAL later
|
actualbal = finalsinglebal -- just check the single-commodity balance, like Ledger; maybe add ==FULLBAL later
|
||||||
diff = actualbal - assertedbal
|
iswrong = dbgtrace 2 debugmsg $
|
||||||
|
not (isReallyZeroMixedAmount (actualbal - assertedbal))
|
||||||
|
-- bal' /= assertedbal -- MixedAmount's Eq instance currently gets confused by different precisions
|
||||||
|
where
|
||||||
|
debugmsg = "assertions: on " ++ show (postingDate p) ++ " balance of " ++ show assertedcomm
|
||||||
|
++ " in " ++ T.unpack (paccount p) ++ " should be " ++ show assertedbal
|
||||||
|
diff = assertedbal - actualbal
|
||||||
diffplus | isNegativeMixedAmount diff == Just False = "+"
|
diffplus | isNegativeMixedAmount diff == Just False = "+"
|
||||||
| otherwise = ""
|
| otherwise = ""
|
||||||
err = printf (unlines [
|
err = printf (unlines [
|
||||||
"a balance assertion failed on %s",
|
"balance assertion error%s",
|
||||||
"in account %s",
|
|
||||||
"in commodity %s",
|
|
||||||
"asserted balance is %s, calculated balance is %s (difference: %s)",
|
|
||||||
"after posting:",
|
"after posting:",
|
||||||
"%s",
|
"%s",
|
||||||
"%s"
|
"balance assertion details:",
|
||||||
|
"date: %s",
|
||||||
|
"account: %s",
|
||||||
|
"commodity: %s",
|
||||||
|
"calculated: %s",
|
||||||
|
"asserted: %s (difference: %s)"
|
||||||
])
|
])
|
||||||
|
(case ptransaction p of
|
||||||
|
Nothing -> ":" -- shouldn't happen
|
||||||
|
Just t -> printf " in \"%s\" (line %d, column %d):\nin transaction:\n%s" f l c (chomp $ show t) :: String
|
||||||
|
where GenericSourcePos f l c = tsourcepos t)
|
||||||
|
(showPostingLine p)
|
||||||
(showDate $ postingDate p)
|
(showDate $ postingDate p)
|
||||||
(T.unpack $ paccount p) -- XXX pack
|
(T.unpack $ paccount p) -- XXX pack
|
||||||
assertedcomm
|
assertedcomm
|
||||||
(showMixedAmount assertedbal)
|
|
||||||
(showMixedAmount finalsinglebal)
|
(showMixedAmount finalsinglebal)
|
||||||
|
(showMixedAmount assertedbal)
|
||||||
(diffplus ++ showMixedAmount diff)
|
(diffplus ++ showMixedAmount diff)
|
||||||
(showPostingLine p)
|
|
||||||
(case ptransaction p of
|
|
||||||
Nothing -> ""
|
|
||||||
Just t -> printf "in transaction at %s line %d:\n%s" f l (show t) :: String
|
|
||||||
where GenericSourcePos f l _ = tsourcepos t
|
|
||||||
)
|
|
||||||
|
|
||||||
-- Given a sequence of postings to a single account, split it into
|
-- Given a sequence of postings to a single account, split it into
|
||||||
-- sub-sequences consisting of ordinary postings followed by a single
|
-- sub-sequences consisting of ordinary postings followed by a single
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user