Skip to content

Commit

Permalink
Merge pull request #1814 from Xitian9/csverror
Browse files Browse the repository at this point in the history
imp: csv: Give an error if unable to substitute csv templates. (#1803)
  • Loading branch information
Xitian9 authored May 22, 2022
2 parents db26456 + c48d98c commit 15a5d5d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions hledger-lib/Hledger/Read/CsvReader.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,10 +1237,10 @@ renderTemplate rules record t = maybe t mconcat $ parseMaybe

-- | Replace something that looks like a reference to a csv field ("%date" or "%1)
-- with that field's value. If it doesn't look like a field reference, or if we
-- can't find such a field, leave it unchanged.
-- can't find such a field, replace it with the empty string.
replaceCsvFieldReference :: CsvRules -> CsvRecord -> CsvFieldReference -> Text
replaceCsvFieldReference rules record s = case T.uncons s of
Just ('%', fieldname) -> fromMaybe s $ csvFieldValue rules record fieldname
Just ('%', fieldname) -> fromMaybe "" $ csvFieldValue rules record fieldname
_ -> s

-- | Get the (whitespace-stripped) value of a CSV field, identified by its name or
Expand Down
13 changes: 13 additions & 0 deletions hledger/test/csv.test
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,19 @@ $ ./csvtest.sh

>=0

# 51. Throw an error when unable to substitute csv templates
<
"2021-12-23","caffe_siciliaexpenses:cibo:dolce","-10.5"

RULES file

account1 assets:bank:checking
fields date, description, account2, amount

$ ./csvtest.sh
>2 /could not balance this transaction/
>=1

## .
#<
#$ ./csvtest.sh
Expand Down

0 comments on commit 15a5d5d

Please sign in to comment.