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 | ||||
| , balanceTransaction | ||||
| , balanceTransactionHelper | ||||
| , annotateErrorWithTransaction | ||||
|   -- * journal balancing | ||||
| , journalBalanceTransactions | ||||
| , journalCheckBalanceAssertions | ||||
| @ -36,7 +35,7 @@ import Data.Foldable (asum) | ||||
| import Data.Function ((&)) | ||||
| import qualified Data.HashTable.Class as H (toList) | ||||
| 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.Maybe (fromJust, fromMaybe, isJust, isNothing, mapMaybe) | ||||
| import qualified Data.Set as S | ||||
| @ -163,15 +162,21 @@ balanceTransactionHelper bopts t = do | ||||
| -- | Generate a transaction balancing error message, given the transaction | ||||
| -- and one or more suberror messages. | ||||
| transactionBalanceError :: Transaction -> [String] -> String | ||||
| transactionBalanceError t errs = | ||||
|   annotateErrorWithTransaction t $ | ||||
|   intercalate "\n" $ "could not balance this transaction:" : errs | ||||
| 
 | ||||
| annotateErrorWithTransaction :: Transaction -> String -> String | ||||
| annotateErrorWithTransaction t s = | ||||
|   unlines [ sourcePosPairPretty $ tsourcepos t, s | ||||
|           , T.unpack . T.stripEnd $ showTransaction t | ||||
|           ] | ||||
| transactionBalanceError t errs = printf (unlines | ||||
|   [ "unbalanced transaction: %s:", | ||||
|     "%s", | ||||
|     "\n%s" | ||||
|   ]) | ||||
|   (sourcePosPairPretty $ tsourcepos t) | ||||
|   (textChomp ex) | ||||
|   (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 | ||||
| -- 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 | ||||
| 
 | ||||
| $  ./csvtest.sh | ||||
| >2 /could not balance this transaction/ | ||||
| >2 /unbalanced transaction/ | ||||
| >=1 | ||||
| 
 | ||||
| ## .  | ||||
|  | ||||
| @ -46,8 +46,8 @@ Here is the current status | ||||
| |--------------------------|------------|------|-----------|---------|----------|-----------------| | ||||
| | accounts                 | ✓          | ✓    | ✓         | ✓✓      |          |                 | | ||||
| | assertions               | ✓          | ✓    | ✓         | ✓✓      |          |                 | | ||||
| | balanced                 |            | ✓    | -         | ✓       |          |                 | | ||||
| | balancednoautoconversion |            | ✓    | -         | ✓       |          |                 | | ||||
| | balanced                 | ✓          | ✓    | -         | ✓       |          |                 | | ||||
| | balancednoautoconversion | ✓          | ✓    | -         | ✓       |          |                 | | ||||
| | commodities              | ✓          | ✓    | ✓(approx) | ✓✓      |          |                 | | ||||
| | ordereddates             | ✓          | ✓    | ✓         | ✓✓      |          |                 | | ||||
| | parseable                | ✓          | ✓    | ✓         | ✓✓      |          |                 | | ||||
|  | ||||
| @ -1,9 +1,9 @@ | ||||
| $$$ hledger check -f balanced.j | ||||
| >>>2 /hledger: Error: .*balanced.j:3-4 | ||||
| could not balance this transaction: | ||||
| $ hledger check -f balanced.j | ||||
| >2 /hledger: Error: unbalanced transaction: .*balanced.j:3-4: | ||||
| 3 | 2022-01-01 | ||||
|   |     a               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 | ||||
| >>>2 /hledger: Error: .*balancednoautoconversion.j:6-8 | ||||
| could not balance this transaction: | ||||
| $ hledger check balancednoautoconversion -f balancednoautoconversion.j | ||||
| >2 /hledger: Error: unbalanced transaction: .*balancednoautoconversion.j:6-8: | ||||
| 6 | 2022-01-01 | ||||
|   |     a             1 A | ||||
|   |     b            -1 B | ||||
| 
 | ||||
| real postings' sum should be 0 but is:  1 A | ||||
| -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. | ||||
| $ hledger -f- print -x --auto | ||||
| >2 /could not balance/ | ||||
| >2 /unbalanced/ | ||||
| >=1 | ||||
| 
 | ||||
| # 17. Commodity display styles are applied to auto posting amounts. | ||||
|  | ||||
| @ -123,12 +123,12 @@ $ hledger -f- print | ||||
|   b  1B | ||||
| $ hledger -f- print | ||||
| >2 | ||||
| hledger: Error: -:1-3 | ||||
| could not balance this transaction: | ||||
| hledger: Error: unbalanced transaction: -:1-3: | ||||
| 1 | 2020-01-01 | ||||
|   |     a              1A | ||||
|   |     b              1B | ||||
| 
 | ||||
| real postings all have the same sign | ||||
| 2020-01-01 | ||||
|     a              1A | ||||
|     b              1B | ||||
| 
 | ||||
| >=1 | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user