dev: errors: improve timeclock errors

This commit is contained in:
Simon Michael 2022-07-14 19:24:46 +01:00
parent aeae7232ca
commit 78d5939c19
4 changed files with 24 additions and 10 deletions

View File

@ -77,14 +77,17 @@ 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\nExpected timeclock %s entry but got %s.\n" ("%s:\n%s\n%s\n\nExpected timeclock %s entry but got %s.\n"
++"Only one session may be clocked in at a time, so please alternate i and o.") ++"Only one session may be clocked in at a time.\n"
++"Please alternate i and o, beginning with i.")
(sourcePosPretty $ tlsourcepos actual) (sourcePosPretty $ tlsourcepos actual)
(show l ++ " | " ++ show actual) (l ++ " | " ++ show actual)
(replicate (length l) ' ' ++ " |" ++ replicate c ' ' ++ "^")
(show expected) (show expected)
(show $ tlcode actual) (show $ tlcode actual)
where where
l = unPos $ sourceLine $ tlsourcepos actual l = show $ unPos $ sourceLine $ tlsourcepos actual
c = unPos $ sourceColumn $ tlsourcepos actual
-- | Convert a timeclock clockin and clockout entry to an equivalent journal -- | Convert a timeclock clockin and clockout entry to an equivalent journal
-- transaction, representing the time expenditure. Note this entry is not balanced, -- transaction, representing the time expenditure. Note this entry is not balanced,
@ -99,11 +102,16 @@ entryFromTimeclockInOut i o
("%s:\n%s\nThis clockout time (%s) is earlier than the previous clockin.\n" ("%s:\n%s\nThis clockout time (%s) is earlier than the previous clockin.\n"
++"Please adjust it to be later than %s.") ++"Please adjust it to be later than %s.")
(sourcePosPretty $ tlsourcepos o) (sourcePosPretty $ tlsourcepos o)
(unlines [replicate (length l) ' '++ " | " ++ show i, l ++ " | " ++ show o]) (unlines [
replicate (length l) ' '++ " | " ++ show i,
l ++ " | " ++ show o,
(replicate (length l) ' ' ++ " |" ++ replicate c ' ' ++ replicate 19 '^')
])
(show $ tldatetime o) (show $ tldatetime o)
(show $ tldatetime i) (show $ tldatetime i)
where where
l = show $ unPos $ sourceLine $ tlsourcepos o l = show $ unPos $ sourceLine $ tlsourcepos o
c = (unPos $ sourceColumn $ tlsourcepos o) + 2
t = Transaction { t = Transaction {
tindex = 0, tindex = 0,
tsourcepos = (tlsourcepos i, tlsourcepos i), tsourcepos = (tlsourcepos i, tlsourcepos i),

View File

@ -55,8 +55,8 @@ Here is the current status
| parseable-regexps | ✓ | ✓ | ✓ | ✓✓ | ✓ | | parseable-regexps | ✓ | ✓ | ✓ | ✓✓ | ✓ |
| payees | ✓ | ✓ | ✓ | ✓✓ | ✓ | | payees | ✓ | ✓ | ✓ | ✓✓ | ✓ |
| uniqueleafnames | ✓ | ✓ | ✓ | ✓✓ | ✓ | | uniqueleafnames | ✓ | ✓ | ✓ | ✓✓ | ✓ |
| tcclockouttime | ✓ | ✓ | ✓ | ✓ | | | tcclockouttime | ✓ | ✓ | ✓ | ✓ | |
| tcorderedactions | ✓ | ✓ | ✓ | ✓ | | | tcorderedactions | ✓ | ✓ | ✓ | ✓ | |
Key: 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)
@ -111,7 +111,7 @@ Here are some current limitations of hledger's error messages:
<!-- to update: make readme --> <!-- to update: make readme -->
<!-- GENERATED: --> <!-- GENERATED: -->
hledger 1.26.99-g32c7f6300-20220714 error messages: hledger 1.26.99-gaeae7232c-20220714 error messages:
### accounts ### accounts
``` ```
@ -282,6 +282,7 @@ Consider changing these account names so their last parts are different.
hledger: Error: /Users/simon/src/hledger/hledger/test/errors/./tcclockouttime.timeclock:5:1: hledger: Error: /Users/simon/src/hledger/hledger/test/errors/./tcclockouttime.timeclock:5:1:
| i 2022-01-01 00:01:00 | i 2022-01-01 00:01:00
5 | o 2022-01-01 00:00:00 5 | o 2022-01-01 00:00:00
| ^^^^^^^^^^^^^^^^^^^
This clockout time (2022-01-01 00:00:00) is earlier than the previous clockin. This clockout time (2022-01-01 00:00:00) is earlier than the previous clockin.
Please adjust it to be later than 2022-01-01 00:01:00. Please adjust it to be later than 2022-01-01 00:01:00.
@ -292,8 +293,10 @@ Please adjust it to be later than 2022-01-01 00:01:00.
``` ```
hledger: Error: /Users/simon/src/hledger/hledger/test/errors/./tcorderedactions.timeclock:8:1: hledger: Error: /Users/simon/src/hledger/hledger/test/errors/./tcorderedactions.timeclock:8:1:
8 | i 2022-01-01 00:01:00 8 | i 2022-01-01 00:01:00
| ^
Expected timeclock o entry but got i. Expected timeclock o entry but got i.
Only one session may be clocked in at a time, so please alternate i and o. Only one session may be clocked in at a time.
Please alternate i and o, beginning with i.
``` ```

View File

@ -2,6 +2,7 @@ $$$ hledger check -f tcclockouttime.timeclock
>>>2 /hledger: Error: .*tcclockouttime.timeclock:5:1: >>>2 /hledger: Error: .*tcclockouttime.timeclock:5:1:
\| i 2022-01-01 00:01:00 \| i 2022-01-01 00:01:00
5 \| o 2022-01-01 00:00:00 5 \| o 2022-01-01 00:00:00
\| \^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^
This clockout time \(2022-01-01 00:00:00\) is earlier than the previous clockin. This clockout time \(2022-01-01 00:00:00\) is earlier than the previous clockin.
Please adjust it to be later than 2022-01-01 00:01:00. Please adjust it to be later than 2022-01-01 00:01:00.

View File

@ -1,8 +1,10 @@
$$$ hledger check -f tcorderedactions.timeclock $$$ hledger check -f tcorderedactions.timeclock
>>>2 /hledger: Error: .*tcorderedactions.timeclock:8:1: >>>2 /hledger: Error: .*tcorderedactions.timeclock:8:1:
8 \| i 2022-01-01 00:01:00 8 \| i 2022-01-01 00:01:00
\| \^
Expected timeclock o entry but got i. Expected timeclock o entry but got i.
Only one session may be clocked in at a time, so please alternate i and o. Only one session may be clocked in at a time.
Please alternate i and o, beginning with i.
/ /
>>>= 1 >>>= 1