diff --git a/hledger-lib/Hledger/Data/Timeclock.hs b/hledger-lib/Hledger/Data/Timeclock.hs index 4fb93e769..7acd2d3fa 100644 --- a/hledger-lib/Hledger/Data/Timeclock.hs +++ b/hledger-lib/Hledger/Data/Timeclock.hs @@ -77,7 +77,7 @@ timeclockEntriesToTransactions now (i:o:rest) errorExpectedCodeButGot :: TimeclockCode -> TimeclockEntry -> a 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" ++"Please alternate i and o, beginning with i.") (sourcePosPretty $ tlsourcepos actual) diff --git a/hledger-lib/Hledger/Read/CsvReader.hs b/hledger-lib/Hledger/Read/CsvReader.hs index e249af383..8170762b0 100644 --- a/hledger-lib/Hledger/Read/CsvReader.hs +++ b/hledger-lib/Hledger/Read/CsvReader.hs @@ -999,17 +999,22 @@ getAmount rules record currency p1IsVirtual n = in case discardExcessZeros $ discardUnnumbered assignments of [] -> Nothing [(f,a)] -> Just $ negateIfOut f a - fs -> error' . T.unpack . T.unlines $ -- PARTIAL: - ["multiple non-zero amounts assigned," - ,"please ensure just one. (https://hledger.org/csv.html#amount)" - ," " <> showRecord record - ," for posting: " <> T.pack (show n) + fs -> error' . T.unpack . textChomp . T.unlines $ -- PARTIAL: + ["in CSV rules:" + ,"While processing " <> showRecord record + ,"while calculating amount for posting " <> T.pack (show n) ] ++ - [" assignment: " <> f <> " " <> + ["rule \"" <> f <> " " <> fromMaybe "" (hledgerField rules record f) <> - "\t=> value: " <> wbToText (showMixedAmountB noColour a) -- XXX not sure this is showing all the right info - | (f,a) <- fs] - + "\" assigned value \"" <> wbToText (showMixedAmountB noColour a) <> "\"" -- XXX not sure this is showing all the right info + | (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, -- if any (and its parse position). 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. 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 -- the value template ultimately assigned to this field, if any, by a field diff --git a/hledger/test/errors/README.md b/hledger/test/errors/README.md index 7d995b097..04372f404 100644 --- a/hledger/test/errors/README.md +++ b/hledger/test/errors/README.md @@ -81,7 +81,7 @@ Here are some current limitations of hledger's error messages: ## Current status Here is the current status as of -hledger 1.26.99-gaeae7232c-20220714, flycheck-hledger g1310cb518. +hledger (see version below) and flycheck-hledger g1310cb518. 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) @@ -105,7 +105,7 @@ Click error names to see an example. Key: | [uniqueleafnames](#uniqueleafnames) | ✓ | ✓ | ✓ | ✓✓ | ✓ | | [tcclockouttime](#tcclockouttime) | ✓ | ✓ | ✓ | ✓✓ | | | [tcorderedactions](#tcorderedactions) | ✓ | ✓ | ✓ | ✓✓ | | -| [csvamountonenonzero](#csvamountonenonzero) | | | | | | +| [csvamountonenonzero](#csvamountonenonzero) | semi-std | | | | | | [csvamountparse](#csvamountparse) | | | | | | | [csvbalanceparse](#csvbalanceparse) | | | | | | | [csvbalancetypeparse](#csvbalancetypeparse) | | | | | | @@ -130,7 +130,7 @@ Click error names to see an example. Key: (To update: `make readme`) -hledger 1.26.99-gaeae7232c-20220714 error messages: +hledger 1.26.99-ga7b920750-20220715 error messages: ### accounts ``` @@ -314,7 +314,7 @@ hledger: Error: /Users/simon/src/hledger/hledger/test/errors/./tcorderedactions. 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. Please alternate i and o, beginning with i. ``` @@ -322,19 +322,23 @@ Please alternate i and o, beginning with i. ### csvamountonenonzero ``` -hledger: Error: multiple non-zero amounts assigned, -please ensure just one. (https://hledger.org/csv.html#amount) - record values: "2022-01-03","1","2" - for posting: 1 - assignment: amount-in %2 => value: 1 - assignment: amount-out %3 => value: 2 +hledger: Error: in CSV rules: +While processing CSV record: "2022-01-03","1","2" +while calculating amount for posting 1 +rule "amount-in %2" assigned value "1" +rule "amount-out %3" assigned 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 ``` 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 date rule is: %1 @@ -352,7 +356,7 @@ you may need to change your amount*, balance*, or currency* rules, or add or cha ### csvbalanceparse ``` 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 date rule is: %1 @@ -368,7 +372,7 @@ expecting '+', '-', or number ### csvbalancetypeparse ``` 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 date rule is: %1 ``` @@ -377,7 +381,7 @@ the date rule is: %1 ### csvdateformat ``` 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-format is: unspecified 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 ``` 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-format is: %Y-%m-%d you may need to change your date rule, change your date-format rule, or change your skip rule diff --git a/hledger/test/errors/csvamountonenonzero.test b/hledger/test/errors/csvamountonenonzero.test index bba33dc90..1ab7b0bbe 100644 --- a/hledger/test/errors/csvamountonenonzero.test +++ b/hledger/test/errors/csvamountonenonzero.test @@ -1,10 +1,10 @@ $$$ hledger check -f csvamountonenonzero.csv ->>>2 /hledger: Error: multiple non-zero amounts assigned, -please ensure just one. \(https:\/\/hledger.org\/csv.html#amount\) - record values: "2022-01-03","1","2" - for posting: 1 - assignment: amount-in %2 => value: 1 - assignment: amount-out %3 => value: 2 +>>>2 /hledger: Error: in CSV rules: +While processing CSV record: "2022-01-03","1","2" +while calculating amount for posting 1 +rule "amount-in %2" assigned value "1" +rule "amount-out %3" assigned value "2" -/ +Multiple non-zero amounts were assigned for an amount field. +Please ensure just one non-zero amount i/ >>>= 1 diff --git a/hledger/test/errors/csvamountparse.test b/hledger/test/errors/csvamountparse.test index 4f4281b05..f0a847400 100644 --- a/hledger/test/errors/csvamountparse.test +++ b/hledger/test/errors/csvamountparse.test @@ -1,6 +1,6 @@ $$$ hledger check -f csvamountparse.csv >>>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 date rule is: %1 @@ -11,5 +11,5 @@ the parse error is: 1:10: unexpected end of input expecting '\+', '-', or number -you may need to change your/ +you may need to change your am/ >>>= 1 diff --git a/hledger/test/errors/csvbalanceparse.test b/hledger/test/errors/csvbalanceparse.test index 7b890a1a1..e10d51118 100644 --- a/hledger/test/errors/csvbalanceparse.test +++ b/hledger/test/errors/csvbalanceparse.test @@ -1,6 +1,6 @@ $$$ hledger check -f csvbalanceparse.csv >>>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 date rule is: %1 diff --git a/hledger/test/errors/csvbalancetypeparse.test b/hledger/test/errors/csvbalancetypeparse.test index 5de9aaa6d..9647f92d3 100644 --- a/hledger/test/errors/csvbalancetypeparse.test +++ b/hledger/test/errors/csvbalancetypeparse.test @@ -1,6 +1,6 @@ $$$ hledger check -f csvbalancetypeparse.csv >>>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 date rule is: %1 diff --git a/hledger/test/errors/csvdateformat.test b/hledger/test/errors/csvdateformat.test index 7455d5cc4..e1348d5f1 100644 --- a/hledger/test/errors/csvdateformat.test +++ b/hledger/test/errors/csvdateformat.test @@ -1,8 +1,8 @@ $$$ 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" -record values: "a","b" +CSV record: "a","b" the date rule is: %1 the date-format is: unspecified 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 diff --git a/hledger/test/errors/csvdateparse.test b/hledger/test/errors/csvdateparse.test index ee3f93d0b..b5a605416 100644 --- a/hledger/test/errors/csvdateparse.test +++ b/hledger/test/errors/csvdateparse.test @@ -1,8 +1,8 @@ $$$ hledger check -f csvdateparse.csv >>>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-format is: %Y-%m-%d 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 diff --git a/hledger/test/errors/tcorderedactions.test b/hledger/test/errors/tcorderedactions.test index f9d9cf4bb..f0ccb62c2 100644 --- a/hledger/test/errors/tcorderedactions.test +++ b/hledger/test/errors/tcorderedactions.test @@ -3,7 +3,7 @@ $$$ hledger check -f tcorderedactions.timeclock 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. Please alternate i and o, beginning with i. / diff --git a/hledger/test/timeclock.test b/hledger/test/timeclock.test index 2ac76c933..1a195caef 100644 --- a/hledger/test/timeclock.test +++ b/hledger/test/timeclock.test @@ -46,7 +46,7 @@ $ hledger -f timeclock:- balance < o 2020/1/1 08:00 $ hledger -f timeclock:- balance ->2 /Expected timeclock i entry/ +>2 /Expected a timeclock i entry/ >= !0 # 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 09:00 $ hledger -f timeclock:- balance ->2 /Expected timeclock o entry/ +>2 /Expected a timeclock o entry/ >= !0 # 6. Timeclock amounts are always rounded to two decimal places,