dev: errors: examples and tests of current CSV errors

This commit is contained in:
Simon Michael 2022-07-15 10:02:40 +01:00
parent d0a7154b4a
commit f1e5d7aa30
50 changed files with 253 additions and 0 deletions

View File

@ -0,0 +1,5 @@
#!/usr/bin/env -S hledger print -f
# Non-zero for both amount-in and amount-out.
2022-01-01,1,
2022-01-02,1,0
2022-01-03,1,2
1 #!/usr/bin/env -S hledger print -f
2 # Non-zero for both amount-in and amount-out.
3 2022-01-01,1,
4 2022-01-02,1,0
5 2022-01-03,1,2

View File

@ -0,0 +1,4 @@
skip 2
date %1
amount-in %2
amount-out %3

View File

@ -0,0 +1,10 @@
$$$ hledger print -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
/
>>>= 1

View File

@ -0,0 +1,5 @@
#!/usr/bin/env -S hledger print -f
# Unparseable amount.
2022-01-01,1
2022-01-02,$1
2022-01-03,badamount
1 #!/usr/bin/env -S hledger print -f
2 # Unparseable amount.
3 2022-01-01,1
4 2022-01-02,$1
5 2022-01-03,badamount

View File

@ -0,0 +1,3 @@
skip 2
date %1
amount %2

View File

@ -0,0 +1,15 @@
$$$ hledger print -f csvamountparse.csv
>>>2 /hledger: Error: error: could not parse "badamount" as an amount
record values: "2022-01-03","badamount"
the amount rule is: %2
the date rule is: %1
the parse error is: 1:10:
\|
1 \| badamount
\| \^
unexpected end of input
expecting '\+', '-', or number
you may need to change your/
>>>= 1

View File

@ -0,0 +1,3 @@
#!/usr/bin/env -S hledger print -f
# Unparseable balance amount.
2022-01-03,badbalance
1 #!/usr/bin/env -S hledger print -f
2 # Unparseable balance amount.
3 2022-01-03,badbalance

View File

@ -0,0 +1,3 @@
skip 2
date %1
balance %2

View File

@ -0,0 +1,16 @@
$$$ hledger print -f csvbalanceparse.csv
>>>2 /hledger: Error: error: could not parse "badbalance" as balance1 amount
record values: "2022-01-03","badbalance"
the balance rule is: %2
the date rule is: %1
the parse error is: 1:11:
\|
1 \| badbalance
\| \^
unexpected end of input
expecting '\+', '-', or number
/
>>>= 1

View File

@ -0,0 +1,4 @@
#!/usr/bin/env -S hledger check -f
# See rules.
2022-01-01,1
1 #!/usr/bin/env -S hledger check -f
2 # See rules.
3 2022-01-01,1

View File

@ -0,0 +1,4 @@
skip 2
date %1
balance %2
balance-type badtype

View File

@ -0,0 +1,9 @@
$$$ hledger check -f csvbalancetypeparse.csv
>>>2 /hledger: Error: balance-type "badtype" is invalid. Use =, ==, =\* or ==\*.
record values: "2022-01-01","1"
the balance rule is: %2
the date rule is: %1
/
>>>= 1

View File

@ -0,0 +1,4 @@
#!/usr/bin/env -S hledger print -f
# See rules (missing/bad date-format rule).
# Note check doesn't show this error; print was needed.
a,b
1 #!/usr/bin/env -S hledger print -f
2 # See rules (missing/bad date-format rule).
3 # Note check doesn't show this error; print was needed.
4 a,b

View File

@ -0,0 +1,2 @@
skip 3
date %1

View File

@ -0,0 +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"
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/
>>>= 1

View File

@ -0,0 +1,4 @@
#!/usr/bin/env -S hledger check -f
# Date value not parseable by date-format rule.
2022-01-01,b
baddate,b
1 #!/usr/bin/env -S hledger check -f
2 # Date value not parseable by date-format rule.
3 2022-01-01,b
4 baddate,b

View File

@ -0,0 +1,3 @@
skip 2
date %1
date-format %Y-%m-%d

View File

@ -0,0 +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"
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/
>>>= 1

View File

@ -0,0 +1,3 @@
#!/usr/bin/env -S hledger check -f
# Rules have no date rule.
a,b
1 #!/usr/bin/env -S hledger check -f
2 # Rules have no date rule.
3 a,b

View File

@ -0,0 +1 @@
skip 2

View File

@ -0,0 +1,6 @@
$$$ hledger check -f csvdaterule.csv
>>>2 /hledger: Error: offset=0:
Please specify \(at top level\) the date field. Eg: date %1
/
>>>= 1

View File

@ -0,0 +1,4 @@
#!/usr/bin/env -S hledger check -f
# See rules.
2022-01-01,1.0
1 #!/usr/bin/env -S hledger check -f
2 # See rules.
3 2022-01-01,1.0

View File

@ -0,0 +1,4 @@
skip 2
date %1
amount %2
decimal-mark badmark

View File

@ -0,0 +1,4 @@
$$$ hledger check -f csvdecimalmarkparse.csv
>>>2 /hledger: Error: decimal-mark's argument should be "." or "," \(not "badmark"\)
/
>>>= 1

View File

@ -0,0 +1,3 @@
#!/usr/bin/env -S hledger check -f
# Rules have an empty conditional block.
a,b
1 #!/usr/bin/env -S hledger check -f
2 # Rules have an empty conditional block.
3 a,b

View File

@ -0,0 +1,2 @@
# no (indented) rules following if
if foo

View File

@ -0,0 +1,10 @@
$$$ hledger check -f csvifblocknonempty.csv
>>>2 /hledger: Error: .*csvifblocknonempty.csv.rules:2:1:
\|
2 \| if foo
\| \^
start of conditional block found, but no assignment rules afterward
\(assignment rules in a conditional block should be indented\)
/
>>>= 1

View File

@ -0,0 +1,3 @@
#!/usr/bin/env -S hledger check -f
# See rules.
1 #!/usr/bin/env -S hledger check -f
2 # See rules.

View File

@ -0,0 +1,2 @@
# if table not using valid CSV field names.
if,date,nosuchfield,description

View File

@ -0,0 +1,8 @@
$$$ hledger check -f csviftablefieldnames.csv
>>>2 /hledger: Error: .*csviftablefieldnames.csv.rules:2:9:
\|
2 \| if,date,nosuchfield,description
\| \^\^\^\^\^\^\^\^\^\^\^\^
unexpected "nosuchfield,"
expecting "account1", "account10", "account11", "account12", "account13", "account14", "account15", "account16", "account17", "account18", "/
>>>= 1

View File

@ -0,0 +1,3 @@
#!/usr/bin/env -S hledger check -f
# See rules.
1 #!/usr/bin/env -S hledger check -f
2 # See rules.

View File

@ -0,0 +1,2 @@
# no (indented) rules following if table
if,date,description,comment

View File

@ -0,0 +1,9 @@
$$$ hledger check -f csviftablenonempty.csv
>>>2 /hledger: Error: .*csviftablenonempty.csv.rules:2:1:
\|
2 \| if,date,description,comment
\| \^
start of conditional table found, but no assignment rules afterward
/
>>>= 1

View File

@ -0,0 +1,3 @@
#!/usr/bin/env -S hledger check -f
# See rules.
1 #!/usr/bin/env -S hledger check -f
2 # See rules.

View File

@ -0,0 +1,4 @@
# if table where some records have wrong number of values.
if,date,description
two,val1,val2
one,val1

View File

@ -0,0 +1,9 @@
$$$ hledger check -f csviftablevaluecount.csv
>>>2 /hledger: Error: .*csviftablevaluecount.csv.rules:4:1:
\|
4 \| one,val1
\| \^
line of conditional table should have 2 values, but this one has only 1
/
>>>= 1

View File

View File

@ -0,0 +1,6 @@
#!/usr/bin/env -S hledger check -f
# Trying to include a CSV file.
include csvinclude.csv

View File

@ -0,0 +1,9 @@
$$$ hledger check -f csvnoinclude.j
>>>2 /hledger: Error: .*csvnoinclude.j:4:23:
\|
4 \| include csvinclude.csv
\| \^
No existing files match pattern: csvinclude.csv
/
>>>= 1

View File

@ -0,0 +1,2 @@
#!/usr/bin/env -S hledger check -f
# See rules.
1 #!/usr/bin/env -S hledger check -f
2 # See rules.

View File

@ -0,0 +1,2 @@
date %1
skip badval

View File

@ -0,0 +1,4 @@
$$$ hledger check -f csvskipvalue.csv
>>>2 /hledger: Error: could not parse skip value: "badval"
/
>>>= 1

View File

@ -0,0 +1,6 @@
#!/usr/bin/env -S hledger print -f
# Status value not parseable.
2022-01-01,*
2022-01-02,!
2022-01-03,
2022-01-04,badstatus
1 #!/usr/bin/env -S hledger print -f
2 # Status value not parseable.
3 2022-01-01,*
4 2022-01-02,!
5 2022-01-03,
6 2022-01-04,badstatus

View File

@ -0,0 +1,3 @@
skip 2
date %1
status %2

View File

@ -0,0 +1,12 @@
$$$ hledger print -f csvstatusparse.csv
>>>2 /hledger: Error: error: could not parse "badstatus" as a cleared status \(should be \*, ! or empty\)
the parse error is: 1:1:
\|
1 \| badstatus
\| \^
unexpected 'b'
expecting '!', '\*', or end of input
/
>>>= 1

View File

@ -0,0 +1,4 @@
#!/usr/bin/env -S sh
# Second space above is significant, prevents shelltest's "-w hledger" substitution.
# Try to read CSV from stdin without specifying a rules file.
echo | hledger -fcsv:- check

View File

@ -0,0 +1,4 @@
$$$ sh csvstdinrules.sh
>>>2 /hledger: Error: please use --rules-file when reading CSV from stdin
/
>>>= 1

View File

@ -0,0 +1,5 @@
#!/usr/bin/env -S hledger check -f
# Record(s) have less than two fields.
a,a
b
c,c
1 #!/usr/bin/env -S hledger check -f
2 # Record(s) have less than two fields.
3 a,a
4 b
5 c,c

View File

@ -0,0 +1,2 @@
skip 2
date %1

View File

@ -0,0 +1,4 @@
$$$ hledger check -f csvtwofields.csv
>>>2 /hledger: Error: CSV record \["b"\] has less than two fields
/
>>>= 1