slashdotdash / node-ledger

API for the ledger command-line interface (ledger-cli.org).
MIT License
72 stars 13 forks source link

Output of register is incomplete #11

Open mariosangiorgio opened 7 years ago

mariosangiorgio commented 7 years ago

I have a file with 501 entries, but register is only returning a fraction of them (roughly between 80 and 90). As a further proof that something is broken the callback for .once('end', onEnd) is never called for my full file, but it gets called for much shorter files.

.once('error', onError) is broken as well. A malformed ledger file, even a very short one, doesn't trigger it. I only see a call to .once('end', onEnd).

This seems related to 097bfdf903d21cc5cbbc929f5f320ecde5d34ae3 by @bergie so I suspect all the other functions might be affected as well.

mariosangiorgio commented 7 years ago

Ignore my previous comment, after some debugging I figured out the issue is somewhere else. Look at this minimal reproduction

2016/08/24 * Opening Balance
    Assets:Current  £1,000.00
    Assets:Investments  10.0 "B4PQW15" @ £164.1035
    Equity:Opening Balances
2016/8/25 * Supermarket
    Expenses:Groceries  £5.00
    Assets:Current

The issue is with the commodity name. I must enclose it in quotes because otherwise I'd get this error message.

While parsing file "/Users/mariosangiorgio/Documents/Personal finance/ledger/2016.ledger", line 3:
While parsing posting:
  Assets:Investments    10.0 B4PQW15 @ £164.1035
                     ^^^^^^^^^^^^^^^^^^^^^^^^^
Error: Unexpected char '4' (Note: inline math requires parentheses)

The line gets rendered this way: "2016/08/24",,,true,false,"Opening Balance","Assets:Investments","10.0 \"B4PQW15\" {£164.1035} [16-Aug-24]". The code that deals with escapes seems to get confused as all I get is a single transaction (Opening Balance) with two postings, one to Assets:Current and one to Assets:Investments.