Balance assertion errors now show line of failed assertion posting. Fixes #481.
This commit is contained in:
parent
e33cce52bc
commit
11684843a0
@ -535,7 +535,9 @@ checkBalanceAssertion p@Posting{ pbalanceassertion = Just ass} amt
|
||||
(case ptransaction p of
|
||||
Nothing -> ":" -- shouldn't happen
|
||||
Just t -> printf " in %s:\nin transaction:\n%s"
|
||||
(showGenericSourcePos $ tsourcepos t) (chomp $ show t) :: String)
|
||||
(showGenericSourcePos postingPos) (chomp $ show t) :: String
|
||||
where postingLine = fromJust $ elemIndex p $ tpostings t -- assume postings are in order
|
||||
postingPos = increaseSourceLine (1+postingLine) (tsourcepos t))
|
||||
(showPostingLine p)
|
||||
(showDate $ postingDate p)
|
||||
(T.unpack $ paccount p) -- XXX pack
|
||||
|
||||
@ -42,6 +42,7 @@ module Hledger.Data.Transaction (
|
||||
sourceFilePath,
|
||||
sourceFirstLine,
|
||||
showGenericSourcePos,
|
||||
increaseSourceLine,
|
||||
-- * misc.
|
||||
tests_Hledger_Data_Transaction
|
||||
)
|
||||
@ -81,6 +82,10 @@ sourceFirstLine = \case
|
||||
GenericSourcePos _ line _ -> line
|
||||
JournalSourcePos _ (line, _) -> line
|
||||
|
||||
increaseSourceLine :: Int -> GenericSourcePos -> GenericSourcePos
|
||||
increaseSourceLine val (GenericSourcePos fp line col) = GenericSourcePos fp (line+val) col
|
||||
increaseSourceLine val (JournalSourcePos fp (first, _)) = GenericSourcePos fp (first+val) 0
|
||||
|
||||
showGenericSourcePos :: GenericSourcePos -> String
|
||||
showGenericSourcePos = \case
|
||||
GenericSourcePos fp line column -> show fp ++ " (line " ++ show line ++ ", column " ++ show column ++ ")"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user