Repository navigation
fix(lint): load every lint's ledger through one shared helper, and refuse failed processing in closed-nonempty - #2922
Merged
Merged
Conversation
…fuse failed processing in closed-nonempty Each `rledger lint` subcommand loaded its ledger its own way. Only `linked-transit` refused a ledger whose booking or plugins failed; `closed-nonempty` refused load errors but answered over failed processing, so a ledger with `plugin "no.such.plugin"`, an unbookable transaction and a `close` printed "No accounts closed with a non-zero balance." and exited 0. `transfers` and `control-chars` never looked at load errors. `lint/load.rs` is now the one place lints load from, at three levels: - `load_booked`: refuses load errors, processes as `check` does, refuses booking and plugin failures, and passes every other error through. Used by `linked-transit` (behavior byte-identical) and `closed-nonempty`, which now refuses failed processing and exits 2 when it cannot answer. - `load_clean`: refuses load errors. Used by `transfers --apply`, which refuses before any file is written. - `load_source` + `warn_load_errors`: answers over what parsed, with a `LOAD_ERRORS` warning. Used by `control-chars` (a control character is often what broke the parse) and read-only `transfers`. Refs #2899 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 |
… transaction-site helpers in the shared loader Review round 1 of the shared lint loader. - Every lint exits 2 when it cannot answer (`lint::ERROR_EXIT_CODE` replaces the per-lint `error_exit_code`): `transfers`, including the `--apply` refusal, and `control-chars` on a missing file, as `linked-transit` and `closed-nonempty` already did. 0 means it answered, 1 a finding under an opt-in fail flag. - A load-error refusal or warning lists each parse error as `file:line: Pnnnn: message`, up to ten, then how many more, where it said only `parse errors in <file>`. Done in the lint loader; `LoadError`'s Display is unchanged. - `ErrorIndex` (each remaining processing error on the transaction it sits on) and `TransactionSites` (plugin-inserted transactions with no or a shared location) move from `linked-transit` into `lint/load.rs`, for the cross-group lint to build on. `linked-transit`'s output is unchanged except for the located load-error detail. - Tests that could not fail now can: the booking refusal is asserted by its `BOOK: interpolation failed` location, with booking-only and plugin-only fixtures; dropping the booking refusal fails five tests. - The ag-rledger assertions for the other lints move to their own test, which checks the `ok: false` envelope. - CHANGELOG: the `closed-nonempty` and `transfers` entries move to Breaking, and the `control-chars` note folds into the entry that introduces the lint. Docs: the exit rule, and that a refusal covers the load errors the loader counts as harmless. Refs #2899 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and review nits Review round 2 of the shared lint loader. - `TransactionSites::for_ledger(&ledger)` returns a per-ledger view whose `site` reads that ledger's location counts, replacing `count` + `site`: a lint can no longer read sites against another ledger's counts. - `OutputFormat` moves from `closed_nonempty` into the lint module. - `transfers::run`'s docs say what it does now: a read-only run over load errors answers with a warning, and "cannot answer" exits 2. - The ag-rledger test asserts `error.code` for each missing-file envelope, and the envelope of a refused `transfers --apply`. Refs #2899 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lper # Conflicts: # CHANGELOG.md
…thon runtime A missing Python plugin is E8004 with the Python plugin runtime and E8005 in the release configuration, which ships without it. The refusal tests asserted E8004 and failed in the Slim Build job; they now assert the plugin named in either message. Refs #2899 Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 10, 2026
Brings in #2922. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 10, 2026
Brings in #2922. WASM cache v88 (main holds v87), loader pin 66. Co-Authored-By: Claude Opus 5.5 <[email protected]>
5 of 8 tasks
robcohen
added a commit
that referenced
this pull request
Nov 11, 2026
…id token The control-chars load-error tests from #2922 use the header `* "bell\u{7}" junk`. With this branch the invalid token after the lone string keeps that string in the payee, so the control character is reported in the payee rather than the narration. Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 12, 2026
…d token (#2944) * fix(parser): keep each header string in its own field after an invalid token A transaction whose header holds an invalid token is kept under error recovery, but its payee and narration were read by counting only the strings that survived, so `* "p" <bad>` loaded with no payee and the narration `p`. The LSP, WASM and FFI, which load despite parse errors, showed the shifted fields. Both walks (red `convert_transaction`, green `convert_transaction_header`) now read the fields through one shared rule, `txn_header::header_payee_narration`: an invalid token before the first tag or link holds the string slot it sits in. A lone string followed by one is the payee, with an empty narration; a lone string after one is the narration; two strings are the payee and narration whatever surrounds them. Error counts and spans are unchanged. Loader cache v73, WASM cache v98. Closes #2932 Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(parser): any unexpected header token holds its slot, read by one rule Review round 1 of the header recovery fix (#2932): - A lone string is the payee only when an unexpected token follows it and none comes before it, so `* <bad> "n" <bad>` keeps the narration `n`: a token written after a string no longer changes its field. - Every token the header grammar has no place for holds its slot, not only an invalid token: a number, a currency, an account, `~`, `@`, a brace, a comma, a keyword, a second flag, a mid-line `#!`. `* "p" 123` keeps payee `p`, as `* "p" <bad>` does. - The rule is `txn_header::header_strings`, which returns string indexes, so the typed `ast::Transaction::payee()` / `narration()` accessors use it too and cannot drift from the directive. Formatter output is unchanged. - The loader cache v73 note says the bump only follows the pin convention: that cache is never saved for a load with errors. - The parser corpus baseline entry for lima's ErrorInTransactionLine (`* "Dinner" A:*:B`) moves: `Dinner` is now the payee. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(parser): only an invalid token after a lone header string keeps it the payee Review round 2 of the header recovery fix (#2932): - Narrow the rule to the one token that can have swallowed a string: an invalid token (a mid-line BOM lexes as one). A lone string right after the flag, followed by an invalid token, is the payee with an empty narration. Every other case keeps beancount's count rule, so `* "Coffee" 5.00 USD` (a forgotten newline) keeps the narration `Coffee`, and anything before the string (`* 123 "n" <bad>`, `* 2024-01-03 "n" <bad>`, `* <bad> "n" <bad>`) leaves it the narration. - `header_strings` now reads token kinds only; the date and flag are told apart by position, so the green walk no longer tracks offsets and the dead `k != DATE` guard is gone. - The `tests/ast.rs` flip and the lima parser-corpus manifest change are reverted: neither header has an invalid token. - Cache notes name the actual holders of the skipped versions. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(parser): pin that an invalid token is never the header flag Reword the header_strings doc: a transaction node opens only on a flag token, a string, a tag or a link, not on an invalid token. Add the [date, bad, s, bad] case, so dropping the ERROR_TOKEN guard in the flag arm (which would read the invalid token as the flag and move the string to the payee) fails a test. Co-Authored-By: Claude Opus 5.5 <[email protected]> * chore: re-trigger CI (runs for 9a1d7d7 never left the queue) Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(lint): expect the payee for a lone header string before an invalid token The control-chars load-error tests from #2922 use the header `* "bell\u{7}" junk`. With this branch the invalid token after the lone string keeps that string in the payee, so the control character is reported in the payee rather than the narration. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
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 changed
Every
rledger lintsubcommand now loads its ledger through one shared helper,crates/rustledger/src/cmd/lint/load.rs, which decides which load and processing errors a lint may answer over. It has three levels:load_bookedcheckdoes (plugins within the budget, validation), refuses booking and plugin failures, passes every other error through inLedger::errorslinked-transit,closed-nonemptyload_cleantransfers --applyload_source+warn_load_errorsLOAD_ERRORSwarningcontrol-chars, read-onlytransfersThe refusal messages are the ones
linked-transitalready printed (<file>: cannot inspect source with load errors: ...,<file>: cannot inspect a ledger whose processing failed: ...), anddescribe_errormoved with them.Per lint:
linked-transit: unchanged in behavior. It callsload_bookedinstead of its own copy. Messages, exit codes, JSON and theag-rledgerenvelope are byte-identical, and its tests pass unchanged.closed-nonempty(the fix): it refused load errors but answered over failed processing. It now refuses a ledger whose booking or plugins failed, and exits 2 for every "could not answer" (it exited 1), matchinglinked-transitandcheck. Its load-error message is nowlinked-transit's.transfers --apply: refuses a file with load errors before writing anything. All inputs load before any edit, so a clean input is not written either. Exit 2 (see Review round 1).transfers(read-only): still answers over what parsed. It now warns that the file had load errors.control-chars: still answers over what parsed. A control character is often what broke the parse, and the parser recovers enough to find it:2024-01-02 * "bell\u{7}" junk(P0012) still reportscontrol character in narration: "bell\u{7}". But recovery can also drop a whole transaction ("bell\u{7}" "x" "y" junkyields no finding), so it now warns. It never prints a clean "No control characters" silently.transfersandcontrol-charsnow take the samewarnings/errargumentslinked-transitdoes, so inag-rledgerthe warning is an entry in the envelope'swarnings, with codeLOAD_ERRORS.On canonical-function discipline:
ag-rledgeronly dispatches tolint::run_with_writerand has no loading of its own.check --lint transfersruns on the ledgercheckhas already loaded and reported, so it is not a lint loader. Nothing else runs lints.Why
Issue #2899 proposes a
cross-grouplint, and we said there that loading would first move into a shared helper. Each lint loaded the ledger its own way, and onlylinked-transitrefused failed booking or plugins. This ledger:rledger lint closed-nonemptyprintedNo accounts closed with a non-zero balance.and exited 0.error: <file>: cannot inspect a ledger whose processing failed: <file>:5: BOOK: interpolation failed: ...; E8004: Python plugin "no.such.plugin" ...and exits 2.How to test
cargo test -p rustledger --all-featuresNew tests:
cmd::lint::load::tests::*: booking-only, plugin-only and combined refusals, each asserted by its location; other errors kept; load-error refusal at both refusing levels, including a duplicate include; each parse error named with its line, and the list capped; the warning to a sink or to stderr, and none without errors;ErrorIndexandTransactionSites, plus the two tests moved fromlinked_transit.closed_nonempty::tests:test_run_with_writer_refuses_a_booking_failure,..._refuses_a_plugin_failure, and..._refuses_failed_booking_and_plugins(the exact ledger above).control_chars::tests::test_run_with_writer_answers_over_load_errors_with_a_warning,..._never_reports_clean_silently_over_load_errors,..._writes_the_load_warning_to_err_without_a_sink.transfers::tests::test_run_with_writer_apply_refuses_load_errors_before_writing,test_run_with_writer_preview_warns_on_load_errors.cli_commands_test:test_lint_closed_nonempty_refuses_failed_processing_with_exit_2,test_lint_transfers_apply_refuses_load_errors_and_writes_nothing.ag_rledger_test:test_lint_control_chars_warns_on_load_errors, andtest_lint_every_lint_exits_two_when_it_cannot_answer(see Review round 1).docs/commands/lint.mdhas a new table of what each lint reads and when it refuses, andCHANGELOG.mdhas two Breaking entries (closed-nonempty,transfers) and a note on the entry that introducescontrol-chars.Refs #2899
Review round 1
lint::ERROR_EXIT_CODEreplaces the per-linterror_exit_code.transfers(including the--applyrefusal) andcontrol-charson a missing file now exit 2, where they exited 1.ag-rledgerdoes not map lint exit codes: a lint that cannot answer is an error envelope there ("ok": false,COMMAND_FAILEDorFILE_NOT_FOUND), unchanged.err.contains("; ")was satisfied by the E8004 message alone. The booking refusal is now asserted by its location (<file>:4: BOOK: interpolation failed,:5:in the [Feature]: Opt-in audit for transactions spanning account groups #2899 ledger,:6:behind a two-line plugin fixture). There are booking-only, plugin-only and combined fixtures in bothload::testsandclosed_nonempty::tests. I checked that the tests now catch a regression: with the booking refusal dropped fromload_booked, five tests fail (load_booked_refuses_a_booking_failure,load_booked_names_every_failure,closed_nonempty'srefuses_a_booking_failureandrefuses_failed_booking_and_plugins,linked_transit'srefuses_booking_errors).cross-groupneeds is inlint/load.rs.ErrorIndexplaces each remaining processing error on the transaction it sits on: a validator's error by its span, a plugin's by its file and line anywhere in the transaction's lines.TransactionSites/TransactionSitegive each transaction its identity and printed location. They flag a plugin-inserted transaction with no source location, or one at a location another transaction already has.span_lines,errors_withinand their two tests moved with them, and there is a newtest_error_index_places_errors_on_their_transaction.linked-transituses these helpers. Its unit tests pass. I ran 576linked-transitinvocations against the round-0 binary: 12 inputs (matched, mismatch, missing, complex, errors on legs,check_commodity,forecast,effective_date, include and duplicate input, parse error, missing plugin, unbookable, missing file), 4 account sets, 3 prefixes, text and JSON, with and without--fail-on. 540 are byte-identical in stdout, stderr and exit code. The other 36 are the parse-error input, and only their stderr differs, by the located load-error detail below.file:line: Pnnnn: message, up to ten, then; and N more, where it saidparse errors in <file>. The change is in the lint loader (describe_load_errors, using the load's source map).LoadError's Display is unchanged.docs/commands/lint.mdopens with the exit-rule table. It also says thatload_clean/load_bookedrefuse even the load errors the loader counts as harmless (a duplicate include, an include cycle, an include glob matching nothing), as bean-check reports them. There is a test for the duplicate include.closed-nonempty,transfersandcontrol-charsassertions moved out oftest_lint_linked_transit_exits_two_when_it_cannot_answerintotest_lint_every_lint_exits_two_when_it_cannot_answer. It asserts exit 2 for a missing file for each lint, and forclosed-nonemptyon load errors, a failed plugin and a failed booking: exit 2, empty stdout, and an"ok": false/COMMAND_FAILEDenvelope whose message says why.closed-nonemptyandtransfersentries are under Breaking, since both lints shipped in v0.24.0. They say "asrledger checkdoes on a file it cannot read". Thecontrol-charsnote is folded into the entry that introduces the lint.Review round 2
TransactionSites::for_ledger(&ledger)returns a per-ledger view (LedgerSites) whosesitereads that ledger's location counts, so a lint cannot read sites against stale counts.OutputFormatmoved fromclosed_nonemptyinto the lint module.transfers::run's docs describe the read-only warning and the exit 2.FILE_NOT_FOUNDfor each missing-file envelope, and theCOMMAND_FAILEDenvelope of a refusedtransfers --apply.🤖 Generated with Claude Code