Repository navigation
Description
rledger query and rledger report return exit 0 on a file they failed to parse, and emit data derived from the partially-parsed ledger. rledger check on the same file correctly fails.
Any automation that pipes rledger query --format csv into another tool receives silently wrong numbers alongside a success status.
Repro
2020-01-01 open Assets:A
this is not valid beancount at all !!!
2020-01-02 * "x"
Assets:A 5 USD
Assets:A -5 USD
$ rledger check broken.beancount ; echo "exit=$?"
...error...
exit=2
$ rledger query --format csv broken.beancount "SELECT account, sum(number) AS n GROUP BY account" ; echo "exit=$?"
account,n
Assets:A,0
exit=0 # <-- success, with data from a file that does not parse
$ rledger report broken.beancount balances ; echo "exit=$?"
exit=0The parse error IS written to stderr (LOAD: parse errors in ...), so an interactive user sees it. Automation checking $?, or consuming stdout, gets no signal at all.
Why this matters more than a usual exit-code nit
The output is not empty, it is plausible. Assets:A,0 looks like a real answer. For a tool whose entire job is producing numbers people rely on, "confidently wrong and reporting success" is the worst available failure mode — worse than crashing.
It also means check and query disagree about whether a file is usable, so a CI pipeline that gates on check and then reports with query is inconsistent with itself.
How it was found
By deepening the beancount oracle to compare values rather than shapes (see the linked PR). The existing comprehensive compat test compares check_match, accounts_match, posting_count_match and error_presence_match — how MANY postings and WHETHER there was an error, never an amount. This class of bug is invisible to it by construction.
Second, smaller finding from the same run
rledger cannot parse non-ASCII account names that beancount accepts:
$ grep CORP ledger_unicode.beancount
Assets:CORP✨ 100 CORP {1 USD}
$ rledger query --format csv ledger_unicode.beancount "SELECT DISTINCT account"
account
Assets:Cash
Assets:CORP # <-- truncated at the non-ASCII characterbeancount reports 0 errors on that file and the account Assets:CORP✨. rledger reports a parse error, and the truncation means Assets:CORP✨ and Assets:CORP would collide. Worth its own issue if the exit-code behaviour above is fixed first — with a hard failure, the truncated account never reaches a result set.
Suggested decision
Whether query/report should hard-fail on parse errors, or gain a --allow-errors style opt-in for the interactive case, is a policy call rather than an obvious fix — hence filing rather than patching.
Activity
feat(compat): widen the value oracle to files with non-fatal errors
robcohen commentedon Jul 31, 2026
Correction: this is beancount-compatible behavior, not a divergence
I filed this as a plain bug. Before fixing it I checked what bean-query actually does, and it does the same thing:
Byte-identical to rledger, same exit code. And beancount's loader behaves the same way underneath — on a file with a
LexerErrorit still returns the one valid transaction:The rledger code says so explicitly, and it is deliberate:
So rledger is not misbehaving here. It is faithfully matching the reference implementation.
What the question actually is
Not "fix a bug" but "do we deliberately deviate from beancount?" — which
CLAUDE.md's compatibility policy has a bucket for:The case for deviating:
Assets:A 0looks like an answer.rledger checkalready exits non-zero on the same file, so the CLI contradicts itself: one command calls the file unusable, another reports on it and claims success.query --format csvhas no signal at all — the parse error only reaches stderr.The case against:
KNOWN_RUST_DIVERGENCES.A narrower option
Fail only on parse errors, leave validation errors (unopened account, failed assertion) reporting exactly as now. That keeps compat for the common messy-ledger case, where beancount's own booking is sound, and refuses only when the entry stream is genuinely incomplete. It is a much smaller deviation and it targets precisely the case where the numbers are untrustworthy.
Deferring to a maintainer decision rather than changing beancount-compatible behavior unilaterally.
feat(compat): compare booked values against beancount, not just shapes (
refactor: one rule for when a query answers despite load errors (#2881)