imp: balanced, balancednoautoconversion: use new error format (#1436)
This commit is contained in:
		
							parent
							
								
									b7e6583a72
								
							
						
					
					
						commit
						1da7d4b7f7
					
				| @ -18,7 +18,6 @@ module Hledger.Data.Balancing | |||||||
| , isTransactionBalanced | , isTransactionBalanced | ||||||
| , balanceTransaction | , balanceTransaction | ||||||
| , balanceTransactionHelper | , balanceTransactionHelper | ||||||
| , annotateErrorWithTransaction |  | ||||||
|   -- * journal balancing |   -- * journal balancing | ||||||
| , journalBalanceTransactions | , journalBalanceTransactions | ||||||
| , journalCheckBalanceAssertions | , journalCheckBalanceAssertions | ||||||
| @ -36,7 +35,7 @@ import Data.Foldable (asum) | |||||||
| import Data.Function ((&)) | import Data.Function ((&)) | ||||||
| import qualified Data.HashTable.Class as H (toList) | import qualified Data.HashTable.Class as H (toList) | ||||||
| import qualified Data.HashTable.ST.Cuckoo as H | import qualified Data.HashTable.ST.Cuckoo as H | ||||||
| import Data.List (intercalate, partition, sortOn) | import Data.List (partition, sortOn) | ||||||
| import Data.List.Extra (nubSort) | import Data.List.Extra (nubSort) | ||||||
| import Data.Maybe (fromJust, fromMaybe, isJust, isNothing, mapMaybe) | import Data.Maybe (fromJust, fromMaybe, isJust, isNothing, mapMaybe) | ||||||
| import qualified Data.Set as S | import qualified Data.Set as S | ||||||
| @ -163,15 +162,21 @@ 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 = | transactionBalanceError t errs = printf (unlines | ||||||
|   annotateErrorWithTransaction t $ |   [ "unbalanced transaction: %s:", | ||||||
|   intercalate "\n" $ "could not balance this transaction:" : errs |     "%s", | ||||||
| 
 |     "\n%s" | ||||||
| annotateErrorWithTransaction :: Transaction -> String -> String |   ]) | ||||||
| annotateErrorWithTransaction t s = |   (sourcePosPairPretty $ tsourcepos t) | ||||||
|   unlines [ sourcePosPairPretty $ tsourcepos t, s |   (textChomp ex) | ||||||
|           , T.unpack . T.stripEnd $ showTransaction t |   (chomp $ unlines errs) | ||||||
|           ] |   where | ||||||
|  |     (_f,_l,_mcols,ex) = makeTransactionErrorExcerpt t finderrcols | ||||||
|  |       where | ||||||
|  |         finderrcols _ = Nothing | ||||||
|  |         -- finderrcols t = Just (1, Just w) | ||||||
|  |         --   where | ||||||
|  |         --     w = maximumDef 1 $ map T.length $ T.lines $ showTransaction t | ||||||
| 
 | 
 | ||||||
| -- | Infer up to one missing amount for this transactions's real postings, and | -- | Infer up to one missing amount for this transactions's real postings, and | ||||||
| -- likewise for its balanced virtual postings, if needed; or return an error | -- likewise for its balanced virtual postings, if needed; or return an error | ||||||
|  | |||||||
| @ -1039,7 +1039,7 @@ account1 assets:bank:checking | |||||||
| fields date, description, account2, amount | fields date, description, account2, amount | ||||||
| 
 | 
 | ||||||
| $  ./csvtest.sh | $  ./csvtest.sh | ||||||
| >2 /could not balance this transaction/ | >2 /unbalanced transaction/ | ||||||
| >=1 | >=1 | ||||||
| 
 | 
 | ||||||
| ## .  | ## .  | ||||||
|  | |||||||
| @ -46,8 +46,8 @@ Here is the current status | |||||||
| |--------------------------|------------|------|-----------|---------|----------|-----------------| | |--------------------------|------------|------|-----------|---------|----------|-----------------| | ||||||
| | accounts                 | ✓          | ✓    | ✓         | ✓✓      |          |                 | | | accounts                 | ✓          | ✓    | ✓         | ✓✓      |          |                 | | ||||||
| | assertions               | ✓          | ✓    | ✓         | ✓✓      |          |                 | | | assertions               | ✓          | ✓    | ✓         | ✓✓      |          |                 | | ||||||
| | balanced                 |            | ✓    | -         | ✓       |          |                 | | | balanced                 | ✓          | ✓    | -         | ✓       |          |                 | | ||||||
| | balancednoautoconversion |            | ✓    | -         | ✓       |          |                 | | | balancednoautoconversion | ✓          | ✓    | -         | ✓       |          |                 | | ||||||
| | commodities              | ✓          | ✓    | ✓(approx) | ✓✓      |          |                 | | | commodities              | ✓          | ✓    | ✓(approx) | ✓✓      |          |                 | | ||||||
| | ordereddates             | ✓          | ✓    | ✓         | ✓✓      |          |                 | | | ordereddates             | ✓          | ✓    | ✓         | ✓✓      |          |                 | | ||||||
| | parseable                | ✓          | ✓    | ✓         | ✓✓      |          |                 | | | parseable                | ✓          | ✓    | ✓         | ✓✓      |          |                 | | ||||||
|  | |||||||
| @ -1,9 +1,9 @@ | |||||||
| $$$ hledger check -f balanced.j | $ hledger check -f balanced.j | ||||||
| >>>2 /hledger: Error: .*balanced.j:3-4 | >2 /hledger: Error: unbalanced transaction: .*balanced.j:3-4: | ||||||
| could not balance this transaction: | 3 | 2022-01-01 | ||||||
|  |   |     a               1 | ||||||
|  | 
 | ||||||
| real postings' sum should be 0 but is: 1 | real postings' sum should be 0 but is: 1 | ||||||
| 2022-01-01 |  | ||||||
|     a               1 |  | ||||||
| 
 | 
 | ||||||
| / | / | ||||||
| >>>= 1 | >= 1 | ||||||
| @ -1,11 +1,11 @@ | |||||||
| $$$ hledger check balancednoautoconversion -f balancednoautoconversion.j | $ hledger check balancednoautoconversion -f balancednoautoconversion.j | ||||||
| >>>2 /hledger: Error: .*balancednoautoconversion.j:6-8 | >2 /hledger: Error: unbalanced transaction: .*balancednoautoconversion.j:6-8: | ||||||
| could not balance this transaction: | 6 | 2022-01-01 | ||||||
|  |   |     a             1 A | ||||||
|  |   |     b            -1 B | ||||||
|  | 
 | ||||||
| real postings' sum should be 0 but is:  1 A | real postings' sum should be 0 but is:  1 A | ||||||
| -1 B | -1 B | ||||||
| 2022-01-01 |  | ||||||
|     a             1 A |  | ||||||
|     b            -1 B |  | ||||||
| 
 | 
 | ||||||
| / | / | ||||||
| >>>= 1 | >= 1 | ||||||
| @ -323,7 +323,7 @@ $ hledger -f- register --auto | |||||||
| 
 | 
 | ||||||
| # 16. No, transaction must be balanced both with and without auto postings. | # 16. No, transaction must be balanced both with and without auto postings. | ||||||
| $ hledger -f- print -x --auto | $ hledger -f- print -x --auto | ||||||
| >2 /could not balance/ | >2 /unbalanced/ | ||||||
| >=1 | >=1 | ||||||
| 
 | 
 | ||||||
| # 17. Commodity display styles are applied to auto posting amounts. | # 17. Commodity display styles are applied to auto posting amounts. | ||||||
|  | |||||||
| @ -123,12 +123,12 @@ $ hledger -f- print | |||||||
|   b  1B |   b  1B | ||||||
| $ hledger -f- print | $ hledger -f- print | ||||||
| >2 | >2 | ||||||
| hledger: Error: -:1-3 | hledger: Error: unbalanced transaction: -:1-3: | ||||||
| could not balance this transaction: | 1 | 2020-01-01 | ||||||
|  |   |     a              1A | ||||||
|  |   |     b              1B | ||||||
|  | 
 | ||||||
| real postings all have the same sign | real postings all have the same sign | ||||||
| 2020-01-01 |  | ||||||
|     a              1A |  | ||||||
|     b              1B |  | ||||||
| 
 | 
 | ||||||
| >=1 | >=1 | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user