Repository navigation
fix(validate): no balance error for a transaction a column-0 invalid token breaks into, as in beancount - #2986
Merged
Merged
Conversation
…token breaks into, as in beancount An unbalanced transaction followed directly (no blank or column-0 comment line between) by a line led by a token beancount's lexer rejects got an E3001 beside the token's parse error. bean-check 3.2.3 fails the statement at that token and its recovery discards the transaction, so the token is the one error there. transaction_holds_invalid_token already answered true for a line a mid-file BOM starts there (#2956). Its next-sibling branch now asks line_leads_with_an_invalid_token, which reuses the parser's own rules for what beancount's lexer rejects: an invalid token, a date that is no calendar date (parse_date_token), a number beancount refuses (holds_a_misgrouped_number), a lone capital glued to what follows it (holds_a_glued_lone_capital), and BOMs not read into an account (bom_led_account). A line led by a token beancount lexes keeps the transaction and its residual. holds_a_misgrouped_number now accepts beancount's one doubled comma after a single digit (1,,000), which its validator takes as a number; checked over every run of digits and commas up to nine long. Measured against beancount's full loader on 19,376 generated ledgers: every residual decision matches (2,379 gained, 0 regressed). WASM cache v120; the loader cache is unchanged (every affected source has a parse error). Closes #2976 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
📊 Benchmark Results
vs base, measured in this run
A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: What do these numbers mean?
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
This was referenced Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
An unbalanced transaction followed directly (no blank or column-0 comment line between) by a line that starts with a token beancount's lexer rejects no longer gets an
E3001beside the token's parse error. bean-check 3.2.3 fails the statement at that token and its recovery discards the transaction, so the token is the one error there.P0012, line 3E3001P0012Why and how
#2984 (#2956) already made
transaction_holds_invalid_tokenanswer true for a line a mid-file BOM starts right after a transaction's block. Its next-sibling branch now calls a new helper,line_leads_with_an_invalid_token, which reuses the parser's existing rules for what beancount's lexer rejects instead of adding a copy:$x,x,k:,'Z,=,\,€, a control character)ERROR_TOKEN2024-13-45,2024-02-30)parse_date_token1,50,1,0)holds_a_misgrouped_numberT@,X(,P")holds_a_glued_lone_capital<BOM>$x)bom_led_account(unchanged)~,*,&, `, a tag, a link,TRUE,{, a string, a valid date,T x`)An indented comment line between the block and the line does not end the block, in beancount or here; a blank or column-0 comment line does, and the residual is reported.
1,,000: checking1,,000showed beancount's number validator accepts one doubled comma after a single digit (1,,000,0,,111,1,,000,000,1,,000.00), though its documented rule does not. I enumerated every run of digits and commas up to nine long through beancount's lexer, and that is the only shape that differs from the strict rule (11,,111,1,,111,,111,1,,,111are errors).holds_a_misgrouped_numbernow accepts it. That predicate is shared with #2985 (#2979), so a quiet line under a failed dated line holding1,,000is now quiet as in beancount (2024-01-02 123 * "n"/Assets:A 1,,000 USD: bean-check {4}, main {4, 5}, this PR {4}).Measurements
Full-check differential: per ledger, whether a balance residual is reported,
rledger check --format json(main 8894a1b and this branch) against beancount'sloader.load_string(3.2.3) in the compat container. Ledgers: 9 transaction shapes (plain, metadata last, transaction metadata, a cost or a price on the last posting, a comment last, one posting, an unknown account, balanced) × 106 column-0 line leads × 4 separators (none, blank line, column-0 comment, indented comment) × LF / CRLF / no final newline, plus two transactions in a row and the leads afterbalance,openandnote.Parse-error parity (pinned fuzz corpus 9bc79f4, compat files, tracked ledgers):
--checkpasses with no regressions and no manifest change.corpus_baselinepasses against the fetched compat corpus.Not changed (documented)
When beancount discards such a transaction it reports none of its other findings either. These stay as on main, as #2956 left them:
E3004one-posting warningE1001unknown accountE2001on abalancedirective followed by such a lineE3004is an rledger addition (#2872 asks whether it is deliberate). The other two would need the validator to treat the whole directive as discarded, not only its residual; that is a larger change than this issue.Caches
CACHE_VERSION119 → 120: both payloads archive validation findings and parse errors, and both move.How to test
The new surface-agreement case puts
$xright after one unbalanced transaction and after a blank line following another; bean-check reports lines 7 and 13 for the tokens and the residual only on line 9, as every surface now does.Closes #2976
🤖 Generated with Claude Code