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