imp: errors: timeclock, csv error improvements
This commit is contained in:
		
							parent
							
								
									ff25ad6767
								
							
						
					
					
						commit
						147856e3bb
					
				| @ -77,7 +77,7 @@ timeclockEntriesToTransactions now (i:o:rest) | |||||||
| 
 | 
 | ||||||
| errorExpectedCodeButGot :: TimeclockCode -> TimeclockEntry -> a | errorExpectedCodeButGot :: TimeclockCode -> TimeclockEntry -> a | ||||||
| errorExpectedCodeButGot expected actual = error' $ printf | errorExpectedCodeButGot expected actual = error' $ printf | ||||||
|   ("%s:\n%s\n%s\n\nExpected timeclock %s entry but got %s.\n" |   ("%s:\n%s\n%s\n\nExpected a timeclock %s entry but got %s.\n" | ||||||
|   ++"Only one session may be clocked in at a time.\n" |   ++"Only one session may be clocked in at a time.\n" | ||||||
|   ++"Please alternate i and o, beginning with i.") |   ++"Please alternate i and o, beginning with i.") | ||||||
|   (sourcePosPretty $ tlsourcepos actual) |   (sourcePosPretty $ tlsourcepos actual) | ||||||
|  | |||||||
| @ -999,17 +999,22 @@ getAmount rules record currency p1IsVirtual n = | |||||||
|   in case discardExcessZeros $ discardUnnumbered assignments of |   in case discardExcessZeros $ discardUnnumbered assignments of | ||||||
|       []      -> Nothing |       []      -> Nothing | ||||||
|       [(f,a)] -> Just $ negateIfOut f a |       [(f,a)] -> Just $ negateIfOut f a | ||||||
|       fs      -> error' . T.unpack . T.unlines $  -- PARTIAL: |       fs      -> error' . T.unpack . textChomp . T.unlines $  -- PARTIAL: | ||||||
|         ["multiple non-zero amounts assigned," |         ["in CSV rules:" | ||||||
|         ,"please ensure just one. (https://hledger.org/csv.html#amount)" |         ,"While processing " <> showRecord record | ||||||
|         ,"  " <> showRecord record |         ,"while calculating amount for posting " <> T.pack (show n) | ||||||
|         ,"  for posting: " <> T.pack (show n) |  | ||||||
|         ] ++ |         ] ++ | ||||||
|         ["  assignment: " <> f <> " " <> |         ["rule \"" <> f <> " " <> | ||||||
|           fromMaybe "" (hledgerField rules record f) <> |           fromMaybe "" (hledgerField rules record f) <> | ||||||
|           "\t=> value: " <> wbToText (showMixedAmountB noColour a) -- XXX not sure this is showing all the right info |           "\" assigned value \"" <> wbToText (showMixedAmountB noColour a) <> "\"" -- XXX not sure this is showing all the right info | ||||||
|         | (f,a) <- fs] |           | (f,a) <- fs | ||||||
| 
 |         ] ++ | ||||||
|  |         ["" | ||||||
|  |         ,"Multiple non-zero amounts were assigned for an amount field." | ||||||
|  |         ,"Please ensure just one non-zero amount is assigned, perhaps with an if rule." | ||||||
|  |         ,"See also: https://hledger.org/hledger.html#setting-amounts" | ||||||
|  |         ,"(hledger manual -> CSV format -> Tips -> Setting amounts)" | ||||||
|  |         ] | ||||||
| -- | Figure out the expected balance (assertion or assignment) specified for posting N, | -- | Figure out the expected balance (assertion or assignment) specified for posting N, | ||||||
| -- if any (and its parse position). | -- if any (and its parse position). | ||||||
| getBalance :: CsvRules -> CsvRecord -> Text -> Int -> Maybe (Amount, SourcePos) | getBalance :: CsvRules -> CsvRecord -> Text -> Int -> Maybe (Amount, SourcePos) | ||||||
| @ -1183,7 +1188,7 @@ negateStr amtstr = case T.uncons amtstr of | |||||||
| 
 | 
 | ||||||
| -- | Show a (approximate) recreation of the original CSV record. | -- | Show a (approximate) recreation of the original CSV record. | ||||||
| showRecord :: CsvRecord -> Text | showRecord :: CsvRecord -> Text | ||||||
| showRecord r = "record values: "<>T.intercalate "," (map (wrap "\"" "\"") r) | showRecord r = "CSV record: "<>T.intercalate "," (map (wrap "\"" "\"") r) | ||||||
| 
 | 
 | ||||||
| -- | Given the conversion rules, a CSV record and a hledger field name, find | -- | Given the conversion rules, a CSV record and a hledger field name, find | ||||||
| -- the value template ultimately assigned to this field, if any, by a field | -- the value template ultimately assigned to this field, if any, by a field | ||||||
|  | |||||||
| @ -81,7 +81,7 @@ Here are some current limitations of hledger's error messages: | |||||||
| ## Current status | ## Current status | ||||||
| 
 | 
 | ||||||
| Here is the current status as of | Here is the current status as of | ||||||
| hledger 1.26.99-gaeae7232c-20220714, flycheck-hledger g1310cb518. <!-- <- MANUALLY KEEP SYNCED WITH GENERATED: BELOW --> | hledger (see version below) and flycheck-hledger g1310cb518. | ||||||
| Click error names to see an example. Key: | Click error names to see an example. Key: | ||||||
| 
 | 
 | ||||||
| - std format - the error message follows a standard format (location on first line, megaparsec-like excerpt, explanation) | - std format - the error message follows a standard format (location on first line, megaparsec-like excerpt, explanation) | ||||||
| @ -105,7 +105,7 @@ Click error names to see an example. Key: | |||||||
| | [uniqueleafnames](#uniqueleafnames)                   | ✓          | ✓    | ✓      | ✓✓      | ✓        | | | [uniqueleafnames](#uniqueleafnames)                   | ✓          | ✓    | ✓      | ✓✓      | ✓        | | ||||||
| | [tcclockouttime](#tcclockouttime)                     | ✓          | ✓    | ✓      | ✓✓      |          | | | [tcclockouttime](#tcclockouttime)                     | ✓          | ✓    | ✓      | ✓✓      |          | | ||||||
| | [tcorderedactions](#tcorderedactions)                 | ✓          | ✓    | ✓      | ✓✓      |          | | | [tcorderedactions](#tcorderedactions)                 | ✓          | ✓    | ✓      | ✓✓      |          | | ||||||
| | [csvamountonenonzero](#csvamountonenonzero)           |            |      |        |         |          | | | [csvamountonenonzero](#csvamountonenonzero)           | semi-std   |      |        |         |          | | ||||||
| | [csvamountparse](#csvamountparse)                     |            |      |        |         |          | | | [csvamountparse](#csvamountparse)                     |            |      |        |         |          | | ||||||
| | [csvbalanceparse](#csvbalanceparse)                   |            |      |        |         |          | | | [csvbalanceparse](#csvbalanceparse)                   |            |      |        |         |          | | ||||||
| | [csvbalancetypeparse](#csvbalancetypeparse)           |            |      |        |         |          | | | [csvbalancetypeparse](#csvbalancetypeparse)           |            |      |        |         |          | | ||||||
| @ -130,7 +130,7 @@ Click error names to see an example. Key: | |||||||
| (To update: `make readme`) | (To update: `make readme`) | ||||||
| 
 | 
 | ||||||
| <!-- GENERATED: --> | <!-- GENERATED: --> | ||||||
| hledger 1.26.99-gaeae7232c-20220714 error messages: | hledger 1.26.99-ga7b920750-20220715 error messages: | ||||||
| 
 | 
 | ||||||
| ### accounts | ### accounts | ||||||
| ``` | ``` | ||||||
| @ -314,7 +314,7 @@ hledger: Error: /Users/simon/src/hledger/hledger/test/errors/./tcorderedactions. | |||||||
| 8 | i 2022-01-01 00:01:00    | 8 | i 2022-01-01 00:01:00    | ||||||
|   | ^ |   | ^ | ||||||
| 
 | 
 | ||||||
| Expected timeclock o entry but got i. | Expected a timeclock o entry but got i. | ||||||
| Only one session may be clocked in at a time. | Only one session may be clocked in at a time. | ||||||
| Please alternate i and o, beginning with i. | Please alternate i and o, beginning with i. | ||||||
| ``` | ``` | ||||||
| @ -322,19 +322,23 @@ Please alternate i and o, beginning with i. | |||||||
| 
 | 
 | ||||||
| ### csvamountonenonzero | ### csvamountonenonzero | ||||||
| ``` | ``` | ||||||
| hledger: Error: multiple non-zero amounts assigned, | hledger: Error: in CSV rules: | ||||||
| please ensure just one. (https://hledger.org/csv.html#amount) | While processing CSV record: "2022-01-03","1","2" | ||||||
|   record values: "2022-01-03","1","2" | while calculating amount for posting 1 | ||||||
|   for posting: 1 | rule "amount-in %2" assigned value "1" | ||||||
|   assignment: amount-in %2	=> value: 1 | rule "amount-out %3" assigned value "2" | ||||||
|   assignment: amount-out %3	=> value: 2 | 
 | ||||||
|  | Multiple non-zero amounts were assigned for an amount field. | ||||||
|  | Please ensure just one non-zero amount is assigned, perhaps with an if rule. | ||||||
|  | See also: https://hledger.org/hledger.html#setting-amounts | ||||||
|  | (hledger manual -> CSV format -> Tips -> Setting amounts) | ||||||
| ``` | ``` | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| ### csvamountparse | ### csvamountparse | ||||||
| ``` | ``` | ||||||
| hledger: Error: error: could not parse "badamount" as an amount | hledger: Error: error: could not parse "badamount" as an amount | ||||||
| record values: "2022-01-03","badamount" | CSV record: "2022-01-03","badamount" | ||||||
| the amount rule is: %2 | the amount rule is: %2 | ||||||
| the date rule is: %1 | the date rule is: %1 | ||||||
| 
 | 
 | ||||||
| @ -352,7 +356,7 @@ you may need to change your amount*, balance*, or currency* rules, or add or cha | |||||||
| ### csvbalanceparse | ### csvbalanceparse | ||||||
| ``` | ``` | ||||||
| hledger: Error: error: could not parse "badbalance" as balance1 amount | hledger: Error: error: could not parse "badbalance" as balance1 amount | ||||||
| record values: "2022-01-03","badbalance" | CSV record: "2022-01-03","badbalance" | ||||||
| the balance rule is: %2 | the balance rule is: %2 | ||||||
| the date rule is: %1 | the date rule is: %1 | ||||||
| 
 | 
 | ||||||
| @ -368,7 +372,7 @@ expecting '+', '-', or number | |||||||
| ### csvbalancetypeparse | ### csvbalancetypeparse | ||||||
| ``` | ``` | ||||||
| hledger: Error: balance-type "badtype" is invalid. Use =, ==, =* or ==*. | hledger: Error: balance-type "badtype" is invalid. Use =, ==, =* or ==*. | ||||||
| record values: "2022-01-01","1" | CSV record: "2022-01-01","1" | ||||||
| the balance rule is: %2 | the balance rule is: %2 | ||||||
| the date rule is: %1 | the date rule is: %1 | ||||||
| ``` | ``` | ||||||
| @ -377,7 +381,7 @@ the date rule is: %1 | |||||||
| ### csvdateformat | ### csvdateformat | ||||||
| ``` | ``` | ||||||
| hledger: Error: error: could not parse "a" as a date using date format "YYYY/M/D", "YYYY-M-D" or "YYYY.M.D" | hledger: Error: error: could not parse "a" as a date using date format "YYYY/M/D", "YYYY-M-D" or "YYYY.M.D" | ||||||
| record values: "a","b" | CSV record: "a","b" | ||||||
| the date rule is:   %1 | the date rule is:   %1 | ||||||
| the date-format is: unspecified | the date-format is: unspecified | ||||||
| you may need to change your date rule, add a date-format rule, or change your skip rule | you may need to change your date rule, add a date-format rule, or change your skip rule | ||||||
| @ -388,7 +392,7 @@ for m/d/y or d/m/y dates, use date-format %-m/%-d/%Y or date-format %-d/%-m/%Y | |||||||
| ### csvdateparse | ### csvdateparse | ||||||
| ``` | ``` | ||||||
| hledger: Error: error: could not parse "baddate" as a date using date format "%Y-%m-%d" | hledger: Error: error: could not parse "baddate" as a date using date format "%Y-%m-%d" | ||||||
| record values: "baddate","b" | CSV record: "baddate","b" | ||||||
| the date rule is:   %1 | the date rule is:   %1 | ||||||
| the date-format is: %Y-%m-%d | the date-format is: %Y-%m-%d | ||||||
| you may need to change your date rule, change your date-format rule, or change your skip rule | you may need to change your date rule, change your date-format rule, or change your skip rule | ||||||
|  | |||||||
| @ -1,10 +1,10 @@ | |||||||
| $$$ hledger check -f  csvamountonenonzero.csv | $$$ hledger check -f  csvamountonenonzero.csv | ||||||
| >>>2 /hledger: Error: multiple non-zero amounts assigned, | >>>2 /hledger: Error: in CSV rules: | ||||||
| please ensure just one. \(https:\/\/hledger.org\/csv.html#amount\) | While processing CSV record: "2022-01-03","1","2" | ||||||
|   record values: "2022-01-03","1","2" | while calculating amount for posting 1 | ||||||
|   for posting: 1 | rule "amount-in %2" assigned value "1" | ||||||
|   assignment: amount-in %2	=> value: 1 | rule "amount-out %3" assigned value "2" | ||||||
|   assignment: amount-out %3	=> value: 2 |  | ||||||
| 
 | 
 | ||||||
| / | Multiple non-zero amounts were assigned for an amount field. | ||||||
|  | Please ensure just one non-zero amount i/ | ||||||
| >>>= 1 | >>>= 1 | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| $$$ hledger check -f  csvamountparse.csv | $$$ hledger check -f  csvamountparse.csv | ||||||
| >>>2 /hledger: Error: error: could not parse "badamount" as an amount | >>>2 /hledger: Error: error: could not parse "badamount" as an amount | ||||||
| record values: "2022-01-03","badamount" | CSV record: "2022-01-03","badamount" | ||||||
| the amount rule is: %2 | the amount rule is: %2 | ||||||
| the date rule is: %1 | the date rule is: %1 | ||||||
| 
 | 
 | ||||||
| @ -11,5 +11,5 @@ the parse error is:      1:10: | |||||||
| unexpected end of input | unexpected end of input | ||||||
| expecting '\+', '-', or number | expecting '\+', '-', or number | ||||||
| 
 | 
 | ||||||
| you may need to change your/ | you may need to change your am/ | ||||||
| >>>= 1 | >>>= 1 | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| $$$ hledger check -f  csvbalanceparse.csv | $$$ hledger check -f  csvbalanceparse.csv | ||||||
| >>>2 /hledger: Error: error: could not parse "badbalance" as balance1 amount | >>>2 /hledger: Error: error: could not parse "badbalance" as balance1 amount | ||||||
| record values: "2022-01-03","badbalance" | CSV record: "2022-01-03","badbalance" | ||||||
| the balance rule is: %2 | the balance rule is: %2 | ||||||
| the date rule is: %1 | the date rule is: %1 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| $$$ hledger check -f  csvbalancetypeparse.csv | $$$ hledger check -f  csvbalancetypeparse.csv | ||||||
| >>>2 /hledger: Error: balance-type "badtype" is invalid. Use =, ==, =\* or ==\*. | >>>2 /hledger: Error: balance-type "badtype" is invalid. Use =, ==, =\* or ==\*. | ||||||
| record values: "2022-01-01","1" | CSV record: "2022-01-01","1" | ||||||
| the balance rule is: %2 | the balance rule is: %2 | ||||||
| the date rule is: %1 | the date rule is: %1 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,8 +1,8 @@ | |||||||
| $$$ hledger print -f  csvdateformat.csv | $$$ hledger print -f  csvdateformat.csv | ||||||
| >>>2 /hledger: Error: error: could not parse "a" as a date using date format "YYYY\/M\/D", "YYYY-M-D" or "YYYY.M.D" | >>>2 /hledger: Error: error: could not parse "a" as a date using date format "YYYY\/M\/D", "YYYY-M-D" or "YYYY.M.D" | ||||||
| record values: "a","b" | CSV record: "a","b" | ||||||
| the date rule is:   %1 | the date rule is:   %1 | ||||||
| the date-format is: unspecified | the date-format is: unspecified | ||||||
| you may need to change your date rule, add a date-format rule, or change your skip rule | you may need to change your date rule, add a date-format rule, or change your skip rule | ||||||
| for m\/d\/y or d\/m\/y d/ | for m\/d\/y or d\/m\/y date/ | ||||||
| >>>= 1 | >>>= 1 | ||||||
|  | |||||||
| @ -1,8 +1,8 @@ | |||||||
| $$$ hledger check -f  csvdateparse.csv | $$$ hledger check -f  csvdateparse.csv | ||||||
| >>>2 /hledger: Error: error: could not parse "baddate" as a date using date format "%Y-%m-%d" | >>>2 /hledger: Error: error: could not parse "baddate" as a date using date format "%Y-%m-%d" | ||||||
| record values: "baddate","b" | CSV record: "baddate","b" | ||||||
| the date rule is:   %1 | the date rule is:   %1 | ||||||
| the date-format is: %Y-%m-%d | the date-format is: %Y-%m-%d | ||||||
| you may need to change your date rule, change your date-format rule, or change your skip rule | you may need to change your date rule, change your date-format rule, or change your skip rule | ||||||
| for m\/d\/y or d\/m\/y dates, use dat/ | for m\/d\/y or d\/m\/y dates, use date-f/ | ||||||
| >>>= 1 | >>>= 1 | ||||||
|  | |||||||
| @ -3,7 +3,7 @@ $$$ hledger check -f  tcorderedactions.timeclock | |||||||
| 8 \| i 2022-01-01 00:01:00    | 8 \| i 2022-01-01 00:01:00    | ||||||
|   \| \^ |   \| \^ | ||||||
| 
 | 
 | ||||||
| Expected timeclock o entry but got i. | Expected a timeclock o entry but got i. | ||||||
| Only one session may be clocked in at a time. | Only one session may be clocked in at a time. | ||||||
| Please alternate i and o, beginning with i. | Please alternate i and o, beginning with i. | ||||||
| / | / | ||||||
|  | |||||||
| @ -46,7 +46,7 @@ $ hledger -f timeclock:- balance | |||||||
| < | < | ||||||
| o 2020/1/1 08:00 | o 2020/1/1 08:00 | ||||||
| $ hledger -f timeclock:- balance | $ hledger -f timeclock:- balance | ||||||
| >2 /Expected timeclock i entry/ | >2 /Expected a timeclock i entry/ | ||||||
| >= !0 | >= !0 | ||||||
| 
 | 
 | ||||||
| # 5. For two consecutive clock-ins, print error | # 5. For two consecutive clock-ins, print error | ||||||
| @ -54,7 +54,7 @@ $ hledger -f timeclock:- balance | |||||||
| i 2020/1/1 08:00 | i 2020/1/1 08:00 | ||||||
| i 2020/1/1 09:00 | i 2020/1/1 09:00 | ||||||
| $ hledger -f timeclock:- balance | $ hledger -f timeclock:- balance | ||||||
| >2 /Expected timeclock o entry/ | >2 /Expected a timeclock o entry/ | ||||||
| >= !0 | >= !0 | ||||||
| 
 | 
 | ||||||
| # 6. Timeclock amounts are always rounded to two decimal places,  | # 6. Timeclock amounts are always rounded to two decimal places,  | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user