Repository navigation
refactor: one rule for when a query answers despite load errors - #2881
Merged
Merged
Conversation
Each query surface decided for itself whether to answer when the load reported errors (#2861): - `rledger query` refused only on a parse or booking error. - WASM `queryMultiFile` and FFI `query-file`, `batch-file` and `session.from-file` refused on every load error except `LoadError::leaves_ledger_complete` (a duplicate include, a cycle or an empty glob). The FFI ones also refused on a plugin error or warning. - WASM `Ledger.fromFiles` / `Ledger.query` never refused. - `rledger doctor roundtrip` kept its own copy of the rule (GlobNoMatch advisory). bean-query 0.2.0, checked in the compat image, answers in every case: missing include, parse error, booking error, include cycle, duplicate include, empty glob and include outside the root. It reports the error and queries the rest. The CLI deliberately refuses on parse and booking errors (#1908, #1987). So the rule is: answer unless parsing or booking failed, and report every load error beside the rows. - rustledger-loader: `LoadError::blocks_queries` (a parse error) and `LedgerError::blocks_queries` (a parse error or a booking failure) express the rule. They replace `LedgerError::leaves_ledger_complete`; `LoadError::leaves_ledger_complete` stays for the doctor's question. - Every query surface calls them: the CLI's `bail_on_parse_errors` / `bail_on_booking_errors`, `queryMultiFile`, `Ledger.fromFiles`, and the FFI file loads. `Ledger` archives `query_refused` in its cache payload (WASM cache v74). - `rledger doctor roundtrip` asks `LoadError::leaves_ledger_complete` instead of its own copy. A duplicate include or an include cycle is now a note there, as an empty glob was. - WIT `rustledger:[email protected]` (API_VERSION 3.17). The docs for `query-file`, `batch-file` and `session.query` state the rule. - Drift guard: one table of ledgers (`query_answer_rule/cases.rs` in rustledger-loader) runs through the predicates, `rledger query`, the FFI file surfaces, and WASM `queryMultiFile` and `Ledger.query` (fresh and from cache). `rledger query` answers and refuses exactly as before. Closes #2861 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✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
# Conflicts: # CHANGELOG.md
…an-query does; exact-row drift guards Review round 1 on #2881. - bean-query 0.2.0 does not answer over every load error: a decryption failure and an I/O error other than not-found (an include naming a directory) raise an uncaught OSError, exit 1, no rows. Answering left the file out silently (a locked gpg-agent made every balance zero). `LoadError::blocks_queries` now also returns true for `Decryption` and for an `Io` error whose kind is not NotFound, so `rledger query` and `rledger report` refuse there too (stricter than before; under Breaking in the CHANGELOG). The CLI gate is `bail_on_load_errors` (was `bail_on_parse_errors`); `bail_on_booking_errors` filters on `is_booking_failure` again, with a debug_assert that the load half was refused first. - The shared drift-guard table states each case's exact rows (or a refusal), the load error that must be reported, and the surfaces it applies to (confined or not; a real filesystem or not). The CLI guard runs `-f json` and checks rows and exit status, so a no-op booking gate now fails it; the FFI and WASM guards check exact rows and the error. New rows: an include naming a directory, a decryption failure, and the out-of-root include split into its confined (rows `pay`, `path traversal` reported) and unconfined (the file read, no error) forms. The FFI guard uses tempfile. - Docs, WIT and CHANGELOG no longer claim bean-query answers over every load error or that every query surface shares the rule: it is the file-based surfaces', and the source-text ones are a follow-up. The `session.from-file` WIT doc states the plugin-error rule. The CHANGELOG mentions the MCP `query_file` tool. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 6, 2026
…ot a missing one Review round 2 on #2881. - MCP `collectLedgerFiles` dropped a file that failed to read for any reason, so the loader reported it missing and `query_file` answered without it. It now drops a file only on ENOENT and throws for anything else (EISDIR, EACCES), so the tool refuses, as `rledger query` and bean-query do. Tests for the collector and the tool. - WASM `queryWithHost` / `validateWithHost` read every throwing host `readFile` as not-found. A throw is now an I/O error, which blocks a query, unless it carries `code: "ENOENT"`; `null` stays not-found. The host contract docs say so. Native test of the mapping and a wasm-bindgen test of `queryWithHost`. - The CLI guard's refusal branch asserts exit code 1 and the gate's "refusing" message, so a panic behind a no-op gate cannot pass. - An include under a directory without read permission refuses (PermissionDenied), where bean-query's glob sees nothing and answers: a documented, tested deliberate deviation, and the docs stop saying every non-NotFound error matches bean-query. - Cite #2882 for the source-text surfaces; align the WASM `query_refused` wording. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # CHANGELOG.md
Review round 3 on #2881. - `queryWithHost` / `validateWithHost` shipped (v0.22.0) with every `readFile` throw meaning not found. Keep that for a throw without a `code`: only an error whose `code` is set and is not ENOENT (EACCES, EISDIR, as Node's fs sets them) is an unreadable file that blocks a query. Docs and CHANGELOG say hosts should set `code`; the wasm-bindgen test covers EACCES and EISDIR (refuse) and ENOENT, a code-less throw and null (answer). - MCP: name the read failure by its code, so the path is not repeated; say in `validate_file` why one unreadable include hides the other diagnostics (the file map cannot hold "exists but unreadable"). - The chmod-000 loader test restores permissions through a drop guard. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # CHANGELOG.md # crates/rustledger-wasm/src/cache.rs
robcohen
added a commit
that referenced
this pull request
Nov 7, 2026
…t does (#2885) * fix(parser): report a line beancount cannot read as often as beancount does Beancount reports an `Invalid token` error for each token its lexer cannot read, and a syntax error only when its grammar fails at a readable token first (once the lexer has reported, bison's recovery reports nothing more for the statement). rledger reported the line error and, on top of it, an inline error for the line's unreadable token, so ` * h` after a transaction's postings, ` k: 1` in a transaction, `Assets:A -39.65 oops NZD` and ` ofxid*: "x"` each gave two overlapping errors where bean-check gives one. `drop_errors_inside_a_line_error` runs on the sorted errors: inside a syntax error, the first generic error on its first line is dropped when the tokens before it are a readable start of an indented line (nothing, a posting flag, an account and a prefix of a plain amount). Later unreadable tokens keep their errors (` * h x` is two, as there), and so does a line whose grammar fails first (` ** h`, ` @ x`, `Assets:A****7f855c`). The outer error is the one kept, since the formatter reads its verbatim-copy ranges from it. A counter test pins it linear. The other #2787 rows (lone `*` line, trailing `*`, one-character key) were already errors as in beancount; they are pinned by tests. - Parser-corpus baseline rows for the three parser-lima error files whose error lists moved (all three now match bean-check's counts); the CST rows do not move. - Loader CACHE_VERSION 59, WASM 76 (v75 is #2881). Closes #2787 Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(parser): name the dropped invalid token in the kept line error Review round 1 on #2787: with the inner error dropped, the editor showed only a whole-line "unexpected input" for ` * h`, where bean-check says `Invalid token: 'h'`. A generic line error that stands for a dropped inner error now reads `unexpected input: invalid token 'h'`, the token escaped and capped at 40 characters. The outer range is unchanged, so the formatter's verbatim-copy ranges are too. The one parser-corpus row whose error text moved (parser-lima examples_data_error-parse) is updated. Also: the dates linear-test doc comment is back on its test, and two long lines are wrapped. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Nov 7, 2026
#2889) * refactor: the source-text query surfaces answer by the file-based rule #2881 gave every file-based query surface one rule for when a query answers despite load errors (`LedgerError::blocks_queries`): refuse on a parse error or a booking failure, otherwise answer and report every load error beside the rows, as bean-query 0.2.0 answers over a plugin's error. The source-text surfaces kept rules of their own, each stricter: - FFI `query`, `batch` and a session from source refused on any load error, a plugin warning included, and `batch` said "parse errors exist" whatever the cause; - WASM `query(source)` (and `balances`) refused on any severity-error, a plugin's or an unresolved include's; - WASM `ParsedLedger.query` refused on any load error; - the MCP `query`, `balances` and `report` tools refused whenever the result held an error, and dropped warnings from an answer. Each now decides with the canonical predicate: the FFI helpers' `LoadResult` carries `error_blocks_queries`, the WASM `ProcessedLedger` carries `query_blocked`, `ParsedLedger` archives `query_refused` (WASM cache v77), and the MCP tools share `queryResponse`. Answered FFI results report the load errors ahead of the query's own, as `batch-file` does. WIT `rustledger:[email protected]`, API_VERSION 3.18. The shared drift-guard table gains a `source_text` flag and a plugin-error case, and runs through FFI `query`, `batch` and a session from source, and WASM `query` and `ParsedLedger.query` fresh and from cache, with exact rows and the reported error. The MCP tests repeat the source-text answers. Also fixes a `clippy::single_match_else` in the FFI guard's `check`, which failed `cargo clippy --workspace --all-targets -D warnings` on main. Closes #2882 Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(wasm): a ledger's query reports its load errors, and the guard tells a refusal by its columns Review round 1 of #2889. - The WASM drift guard asserted a refusal as "no rows, some errors", so a ledger that failed to parse (no entries, so no rows either) passed with its refusal removed: `query_blocked: false` on the parse-error path survived. A refusal must now have no columns, an answer the query's one column, and the load error must be in the result's own `errors`. - `ParsedLedger.query` answered with `errors: []` over a plugin's error or an unresolved include, so a caller reading the result got partial rows with nothing saying so. Its result's `errors` now lead with the load's errors and option diagnostics, as the free `query` reports them. `Ledger.query` (#2861) answered the same way; its answers now carry the ledger's errors too. Method docs and the `.d.ts` say so. - The WIT `batch` doc no longer says each query repeats every load error: semantic validation errors are in `load.errors` only. - MCP `queryResponse` keeps the load's warnings beside a refusal or a BQL error, and a test comment no longer misattributes the 0.24.0 plugin behavior. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(wasm): ParsedLedger.query refuses with option diagnostics too, and document reading a result by its columns Review round 2 of #2889. - A refused `ParsedLedger.query` returned only the load errors; it now adds the option diagnostics, as the free `query` refuses with `reported_errors()`. - The `QueryResult.errors` doc (and the generated bindings) says a result with columns is an answer whatever `errors` holds, and that a refusal has no columns. - CHANGELOG Breaking entry: `Ledger.query` and `ParsedLedger.query` answers can now carry `errors`, which 0.24.0 never did; recognize a refusal by empty `columns`. 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.
Behavior changes (read first)
rledger query(andrledger report) became stricter in one case.OSError, exit 1 and no rows.Everything else on the CLI is unchanged:
report balancespanics on an ambiguous STRICT lot match;query BALANCESprints a wrong row #1987).rledger query/rledger reportqueryMultiFile(and the MCPquery_filetool built on it)query-file,batch-file,session.from-fileunrealizednotice, an unknown session plugin)Ledger.fromFiles/Ledger.queryfromCache); listed under Breaking in the CHANGELOGrledger doctor roundtripThe rule
These are bean-query 0.2.0's results from the rustledger-compat image:
File glob ... does not match any files)Duplicate filename parsed)Duplicate filename parsed)OSError: Could not decrypt file, exit 1, no rowsIsADirectoryError, exit 1, no rowsThe rule for the file-based query surfaces: a query refuses when a file failed to parse, a file that exists could not be read or decrypted, or a transaction failed to book. Otherwise it answers, reporting every load error beside the rows.
query-file,batch-file, a session withoutallow-unrestricted-includes), an include outside the tree is reported and left unread, and the query answers without it. bean-query has no such case.What changed
rustledger-loader: the rule lives in two canonical predicates:
LoadError::blocks_queries: a parse error, a decryption failure, or anIoerror whose kind is notNotFound.LedgerError::blocks_queries: one of those, or a booking failure.They replace
LedgerError::leaves_ledger_complete.LoadError::leaves_ledger_completestays for the doctor's question, "was every file read".Every file-based surface calls them:
bail_on_load_errors(renamed frombail_on_parse_errors; it now also refuses on unreadable files) andbail_on_booking_errors(booking-only filter, with adebug_assertthat the load half was refused first)queryMultiFileLedger.fromFiles, which archivesquery_refusedin its cache payload (WASM cache v75)FileLoad::error_blocks_queries, which feedsquery-file,batch-fileandsession.from-fileFFI contract: WIT
rustledger:[email protected]andAPI_VERSION3.17. The docs forquery-file,batch-file,session.from-fileandsession.querystate the rule, the plugin-error rule and the old behavior.Drift guard: one table,
crates/rustledger-loader/tests/query_answer_rule/cases.rs, shared byinclude!. Each row states the exact rows the query returns (or a refusal), the load error that must be reported, and which surfaces it applies to (confined or unconfined, and whether it needs a real filesystem). It runs through:rledger query -f json(exact rows and exit status)query-file,batch-file, andsession.from-fileboth confined and unrestrictedqueryMultiFile, andLedger.queryfresh and from cacheFollow-up (out of scope here)
The source-text query surfaces keep their own rules:
query,batchandsessionbuilt from source text: they refuse on any load error, plugin warnings included, with a misleading "parse errors exist" message.query(source).ParsedLedger.query.querytool built on them.Tracked in #2882.
Review round 1
blocks_queriesnow returns true forDecryptionand for anIoerror whose kind is notNotFound, which makesrledger querystricter (above). Both cases were added to the shared table. Every "bean-query answers over every load error" claim is corrected: in the loader doc, the CHANGELOG, this body and the WIT docs. The out-of-tree include is now described as rledger confining it and answering without it.stdout.contains("pay"), which passed even withbail_on_booking_errorsmade a no-op. It now runs-f jsonand asserts the exact rows and the exit status, and a refusal must print no rows. Without the booking gate, the booking row would returnpay,buy1,buy2,sell.query_filewould now fail the confined out-of-root row: it expects["pay"]pluspath traversaland would get["pay", "more"].root/../other.beancountis the keyother.beancount, so WASM runs the unconfined row (["pay", "more"], no error) and skips the confined one.wasm-pack test --nodewas run.query_filetool.Ledger.queryrefusal and the CLI's new refusal are under Breaking.tempfile::tempdir().bail_on_booking_errorsfilters onis_booking_failureagain, with a comment and adebug_assert.session.from-fileWIT doc states the plugin-error rule.Review round 2
query_fileno longer answers over an unreadable include.collectLedgerFilesdropped a file that failed to read for any reason, so the loader called it missing and the query answered. It now leaves a file out only onENOENT, and throws for anything else (EISDIR, EACCES), naming the file and the cause. The tool then refuses, asrledger queryand bean-query do. There are new MCP tests forcollectLedgerFilesand thequery_filetool (npm test: 128 pass).queryWithHost/validateWithHost. A hostreadFilethat throws is now an I/O error, which blocks a query. A throw carryingcode: "ENOENT", or anullreturn, is still not-found. ThereadFilecontract docs say so. There is a native test of the mapping and awasm-bindgentest ofqueryWithHost(EACCES refuses, ENOENT answers).query_with_host/validate_with_hostare re-exported from the crate root for that test.PermissionDeniedand refuses. This is recorded in theLoadError::blocks_queriesdoc and the CHANGELOG, and pinned bytest_blocks_queries_refuses_an_include_under_a_locked_directory. The doc no longer says "Matching bean-query" for every non-NotFound error.query_refusedwording (parsed_ledger.rs, cache.rs) now names the full rule.Review round 3
queryWithHost/validateWithHostshipped in v0.22.0 treating anyreadFilethrow as not-found, so a throw without acodestill means not-found. Only an error whosecodeis set and is notENOENT(EACCES,EISDIR, ...) is an unreadable file that blocks the query. Anullreturn stays not-found. ThereadFiledocs and the CHANGELOG entry (under Fixed) say hosts should setcodeto report unreadable files. The wasm-bindgen test covers EACCES and EISDIR (refuse), and ENOENT, a throw without a code, andnull(answer). The native test covers the same mapping.failed to read file <path>: EISDIR), so the path is not repeated.validate_filenow has a comment on why one unreadable include hides the other diagnostics: the file map cannot hold "exists but unreadable".wasm-pack test --node, and MCPnpm test(128 pass).Merge with #2877 and #2883
Merged origin/main, which now has #2877 (loader cache 58, WASM cache 74) and #2883. This PR's WASM cache bump moves to v75:
CACHE_VERSION, its history note and the CHANGELOG entry ("WASM cache v75"). #2877's v74 note is unchanged, and the loader cache is untouched. A tree-wide grep finds exactly one v74 note (#2779) and one v75 note (#2861). Loader, wasm native and CLI guard tests pass, as doeswasm-pack test --node.How to test
Closes #2861
🤖 Generated with Claude Code