fix: errors: omit wrong column numbers in a number of error messages
accounts, commodities, payees, ordereddates, uniqueleafnames The column numbers were accurate for the rendered excerpt but not for the actual data.
This commit is contained in:
parent
77f29aeee9
commit
d07bf4afbb
@ -26,6 +26,7 @@ import Hledger.Utils
|
||||
-- on the transaction line, and a column(s) marker.
|
||||
-- Returns the file path, line number, column(s) if known,
|
||||
-- and the rendered excerpt, or as much of these as is possible.
|
||||
-- A limitation: columns will be accurate for the rendered error message but not for the original journal data.
|
||||
makeTransactionErrorExcerpt :: Transaction -> (Transaction -> Maybe (Int, Maybe Int)) -> (FilePath, Int, Maybe (Int, Maybe Int), Text)
|
||||
makeTransactionErrorExcerpt t findtxnerrorcolumns = (f, tl, merrcols, ex)
|
||||
-- XXX findtxnerrorcolumns is awkward, I don't think this is the final form
|
||||
@ -58,6 +59,7 @@ decorateTransactionErrorExcerpt l mcols txt =
|
||||
-- on the problem posting's line, and a column indicator.
|
||||
-- Returns the file path, line number, column(s) if known,
|
||||
-- and the rendered excerpt, or as much of these as is possible.
|
||||
-- A limitation: columns will be accurate for the rendered error message but not for the original journal data.
|
||||
makePostingErrorExcerpt :: Posting -> (Posting -> Transaction -> Text -> Maybe (Int, Maybe Int)) -> (FilePath, Int, Maybe (Int, Maybe Int), Text)
|
||||
makePostingErrorExcerpt p findpostingerrorcolumns =
|
||||
case ptransaction p of
|
||||
|
||||
@ -41,11 +41,12 @@ journalCheckAccounts j = mapM_ checkacct (journalPostings j)
|
||||
checkacct p@Posting{paccount=a}
|
||||
| a `elem` journalAccountNamesDeclared j = Right ()
|
||||
| otherwise = Left $
|
||||
printf "%s:%d:%d-%d:\n%sundeclared account \"%s\"\n" f l col col2 ex a
|
||||
printf "%s:%d:\n%sundeclared account \"%s\"\n" f l ex a
|
||||
where
|
||||
(f,l,mcols,ex) = makePostingErrorExcerpt p finderrcols
|
||||
col = maybe 0 fst mcols
|
||||
col2 = maybe 0 (fromMaybe 0 . snd) mcols
|
||||
(f,l,_mcols,ex) = makePostingErrorExcerpt p finderrcols
|
||||
-- Calculate columns suitable for highlighting the excerpt.
|
||||
-- We won't show these in the main error line as they aren't
|
||||
-- accurate for the actual data.
|
||||
finderrcols p _ _ = Just (col, Just col2)
|
||||
where
|
||||
col = 5 + if isVirtual p then 1 else 0
|
||||
@ -60,11 +61,9 @@ journalCheckCommodities j = mapM_ checkcommodities (journalPostings j)
|
||||
case findundeclaredcomm p of
|
||||
Nothing -> Right ()
|
||||
Just (comm, _) ->
|
||||
Left $ printf "%s:%d:%d-%d:\n%sundeclared commodity \"%s\"\n" f l col col2 ex comm
|
||||
Left $ printf "%s:%d:\n%sundeclared commodity \"%s\"\n" f l ex comm
|
||||
where
|
||||
(f,l,mcols,ex) = makePostingErrorExcerpt p finderrcols
|
||||
col = maybe 0 fst mcols
|
||||
col2 = maybe 0 (fromMaybe 0 . snd) mcols
|
||||
(f,l,_mcols,ex) = makePostingErrorExcerpt p finderrcols
|
||||
where
|
||||
-- Find the first undeclared commodity symbol in this posting's amount
|
||||
-- or balance assertion amount, if any. The boolean will be true if
|
||||
@ -83,6 +82,10 @@ journalCheckCommodities j = mapM_ checkcommodities (journalPostings j)
|
||||
assertioncomms = [acommodity a | Just a <- [baamount <$> pbalanceassertion]]
|
||||
findundeclared = find (`M.notMember` jcommodities j)
|
||||
|
||||
-- Calculate columns suitable for highlighting the excerpt.
|
||||
-- We won't show these in the main error line as they aren't
|
||||
-- accurate for the actual data.
|
||||
|
||||
-- Find the best position for an error column marker when this posting
|
||||
-- is rendered by showTransaction.
|
||||
-- Reliably locating a problem commodity symbol in showTransaction output
|
||||
@ -119,13 +122,14 @@ journalCheckPayees j = mapM_ checkpayee (jtxns j)
|
||||
checkpayee t
|
||||
| payee `elem` journalPayeesDeclared j = Right ()
|
||||
| otherwise = Left $
|
||||
printf "%s:%d:%d-%d:\n%sundeclared payee \"%s\"\n" f l col col2 ex payee
|
||||
printf "%s:%d:\n%sundeclared payee \"%s\"\n" f l ex payee
|
||||
where
|
||||
payee = transactionPayee t
|
||||
(f,l,mcols,ex) = makeTransactionErrorExcerpt t finderrcols
|
||||
col = maybe 0 fst mcols
|
||||
col2 = maybe 0 (fromMaybe 0 . snd) mcols
|
||||
(f,l,_mcols,ex) = makeTransactionErrorExcerpt t finderrcols
|
||||
-- Calculate columns suitable for highlighting the excerpt.
|
||||
-- We won't show these in the main error line as they aren't
|
||||
-- accurate for the actual data.
|
||||
finderrcols t = Just (col, Just col2)
|
||||
where
|
||||
col = T.length (showTransactionLineFirstPart t) + 2
|
||||
col = T.length (showTransactionLineFirstPart t) + 2
|
||||
col2 = col + T.length (transactionPayee t) - 1
|
||||
|
||||
@ -6,7 +6,6 @@ where
|
||||
import Control.Monad (forM)
|
||||
import Data.List (groupBy)
|
||||
import Text.Printf (printf)
|
||||
import Data.Maybe (fromMaybe)
|
||||
|
||||
import Hledger.Data.Errors (makeTransactionErrorExcerpt)
|
||||
import Hledger.Data.Transaction (transactionFile, transactionDateOrDate2)
|
||||
@ -26,12 +25,10 @@ journalCheckOrdereddates whichdate j = do
|
||||
FoldAcc{fa_previous=Nothing} -> Right ()
|
||||
FoldAcc{fa_error=Nothing} -> Right ()
|
||||
FoldAcc{fa_error=Just t, fa_previous=Just tprev} -> Left $ printf
|
||||
"%s:%d:%d-%d:\n%stransaction date%s is out of order with previous transaction date %s"
|
||||
f l col col2 ex datenum tprevdate
|
||||
"%s:%d:\n%stransaction date%s is out of order with previous transaction date %s"
|
||||
f l ex datenum tprevdate
|
||||
where
|
||||
(f,l,mcols,ex) = makeTransactionErrorExcerpt t finderrcols
|
||||
col = maybe 0 fst mcols
|
||||
col2 = maybe 0 (fromMaybe 0 . snd) mcols
|
||||
(f,l,_mcols,ex) = makeTransactionErrorExcerpt t finderrcols
|
||||
finderrcols _t = Just (1, Just 10)
|
||||
datenum = if whichdate==SecondaryDate then "2" else ""
|
||||
tprevdate = show $ getdate tprev
|
||||
|
||||
@ -11,7 +11,6 @@ import Data.List (groupBy, sortBy)
|
||||
import Data.Text (Text)
|
||||
import qualified Data.Text as T
|
||||
import Text.Printf (printf)
|
||||
import Data.Maybe (fromMaybe)
|
||||
|
||||
import Hledger.Data.AccountName (accountLeafName)
|
||||
import Hledger.Data.Errors (makePostingErrorExcerpt)
|
||||
@ -48,13 +47,11 @@ checkposting leafandfullnames p@Posting{paccount=a} =
|
||||
case [lf | lf@(_,fs) <- leafandfullnames, a `elem` fs] of
|
||||
[] -> Right ()
|
||||
(leaf,fulls):_ -> Left $ printf
|
||||
"%s:%d:%d-%d:\n%saccount leaf name \"%s\" is not unique\nit is used in account names: %s"
|
||||
f l col col2 ex leaf accts
|
||||
"%s:%d:\n%saccount leaf name \"%s\" is not unique\nit is used in account names: %s"
|
||||
f l ex leaf accts
|
||||
where
|
||||
-- t = fromMaybe nulltransaction ptransaction -- XXX sloppy
|
||||
col = maybe 0 fst mcols
|
||||
col2 = maybe 0 (fromMaybe 0 . snd) mcols
|
||||
(f,l,mcols,ex) = makePostingErrorExcerpt p finderrcols
|
||||
(f,l,_mcols,ex) = makePostingErrorExcerpt p finderrcols
|
||||
where
|
||||
finderrcols p _ _ = Just (col, Just col2)
|
||||
where
|
||||
|
||||
Loading…
Reference in New Issue
Block a user