Skip to content

fix(wasm)!: report multi-file errors as rledger check and the FFI do - #2971

Merged
robcohen merged 3 commits into
mainfrom
fix/wasm-multifile-errors
Nov 13, 2026
Merged

robcohen merged 3 commits into
mainfrom
fix/wasm-multifile-errors

Conversation

@robcohen

@robcohen robcohen commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

What

WASM's multi-file surfaces (validateMultiFile, validateWithHost, parseMultiFile, Ledger (fromFiles, getErrors, query), queryMultiFile, queryWithHost) now report errors the way rledger check, the FFI component and the single-source surfaces (validateSource, ParsedLedger) do.

#2961: path prefix on parse error messages

load_errors_to_errors built each parse error from parse_error_fields and then wrote <path>: in front of the message, even though the path is already in file. It now maps parse errors through the loader's canonical rustledger_loader::parse_errors_to_ledger_errors (the function behind the FFI) and places them with a new helpers::ledger_error_to_wasm. The message is the parser's text unchanged. parse_error_fields stays only for the single-source surfaces, which have no LoadError or SourceMap. The paired comments on both sides are updated.

#2964: null ends and missing hints on loader findings

From<LedgerError> for Error set hint: None, and it could not locate the end without the load's SourceMap.

  • From now copies hint, so the multi-file surfaces give a finding or booking error the hint rledger check --format json gives it (E8001's documents-folder hint among them). E2001 has none there, as in check; validateSource gives it one through validation_error_to_wasm's hint, note, context fallback, a pre-existing difference now tracked in WASM validateSource gives E2001 a hint that rledger check and the multi-file surfaces do not #2972. A LOAD error never carries a hint: the loader gives it none, and check adds its include-cycle hint itself (crates/rustledger/src/cmd/check.rs).
  • New ledger_error_to_wasm(LedgerError, &SourceMap) builds on From and adds the end of source_span, located in file_id through the canonical SourceMap::locate. The end stays null when there is no span or start, or when the file id is a placeholder.
  • Every surface that holds the load's SourceMap now converts through it: reported_ledger_errors (which now takes the map), parseMultiFile, and the booking errors of the single-source load_and_book. load_errors_to_errors's include-site arm also locates through SourceMap::locate.

#2960: queryMultiFile lists no option diagnostics on a source that fails to parse

query_with_filesystem refused on a blocking load error before process, so no Ledger existed. It now does what Ledger.fromFiles does: it takes the parse errors out (take_parse_errors), runs process over whatever parsed, refuses on parse_blocks_queries || ledger.blocks_queries(), and lists parse errors, then ledger errors, then Ledger::query_option_errors. In that refusal, other load errors are now reported by process as LOAD, the same as on the path without a parse error, where they were code-less phase: parse errors.

Tests

  • Drift guard parse_error_mapping_parity (crates/rustledger-wasm/src/helpers.rs):
    • The parse-error test now compares every field (message, code, phase, hint, file, line, column, end, severity) across the loader, multi-file load_errors_to_errors and single-source parse_errors_to_wasm. The prefix stripping is gone.
    • New test_multi_file_findings_are_placed_as_validate_source_places_them: on the same ledgers (BOM plus balance, unbalanced transaction with multi-byte account, E4003 booking error, parse error plus a finding), validateSource, validateMultiFile and Ledger.fromFiles give every finding the same code, severity, start and end.
    • New test_multi_file_surfaces_keep_a_loader_findings_hint: E8001's documents-folder hint reaches validateMultiFile and Ledger.fromFiles.
  • wasm-pack node tests:
    • wasm_error_columns.rs expects the real ends on validateMultiFile and now covers Ledger (fresh and from cache) too.
    • wasm_query_option_errors.rs drops the prefix rewrite and the queryMultiFile skip, so the refused-booking-method-with-parse-error case now runs through queryMultiFile.
    • wasm_surface_agreement.rs drops MULTI_FILE_PREFIX.

Cache

WASM CACHE_VERSION 109: a Ledger archives its errors and a ParsedLedger archives its booking errors. 108 is held by #2970 and 106 by #2931. The loader cache is unchanged at 73.

How to test

cargo test -p rustledger-wasm --lib
cargo test -p rustledger-loader
(cd crates/rustledger-wasm && wasm-pack test --node)

Gates run locally: cargo fmt --all --check, cargo clippy --workspace --all-features --all-targets -- -D warnings, RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --all-features --no-deps, cargo test -p rustledger-wasm -p rustledger-loader, wasm-pack test --node.

Breaking (WASM wire output, as in #2946 and #2969): a host that matched on the prefixed parse-error message text must drop the prefix. The CHANGELOG lists it under ### Breaking, with a Fixed bullet pointing to it. rustfava is unaffected, since it embeds the FFI component, not WASM; packages/mcp-server's formatErrors benefits, as it no longer names the file twice (file:line:col: file: message). No Rust public type changed.

Closes #2960
Closes #2961
Closes #2964

🤖 Generated with Claude Code

The multi-file WASM surfaces (validateMultiFile, validateWithHost,
parseMultiFile, Ledger, queryMultiFile, queryWithHost) diverged from
rledger check, the FFI and the single-source surfaces three ways:

- A parse error's message was prefixed with its file path, which is
  already in the error's file field (#2961). load_errors_to_errors now
  maps parse errors through the loader's parse_errors_to_ledger_errors
  and places them with the new ledger_error_to_wasm.
- A loader error (validation finding, booking error, include LOAD error)
  had a null end and no hint, because From<LedgerError> cannot locate the
  end and dropped the hint (#2964). From now copies the hint, and
  ledger_error_to_wasm locates the end of source_span with
  SourceMap::locate; every surface holding the load's SourceMap converts
  through it.
- queryMultiFile / queryWithHost refused on a parse error before process,
  so no Ledger existed and no option diagnostic was listed (#2960). They
  now take the parse errors out and process the rest, as Ledger.fromFiles
  does, and list Ledger::query_option_errors beside them.

The parse_error_mapping_parity drift guard now compares every field, the
end included, and adds two tests: validateSource, validateMultiFile and
Ledger.fromFiles place every finding at the same start and end on the
same ledgers, and the multi-file surfaces keep E8001's hint. The
queryMultiFile skip and the prefix stripping in the wasm-pack tests are
gone. WASM cache v109 (v108 is held by #2970).

Closes #2960
Closes #2961
Closes #2964

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner November 13, 2026 05:31
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 32.9ms ± 1.1ms 435.7ms ± 7.7ms 13.2x 44.9 MB / 51.0 MB
investment 49.2ms ± 0.8ms 1452.9ms ± 17.7ms 29.5x 47.1 MB / 58.9 MB
fifo 47.2ms ± 0.5ms 7752.2ms ± 182.4ms 164.2x 48.9 MB / 58.8 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 32.7ms ± 0.4ms 32.9ms ± 1.1ms +0.8% ✅ within noise 45.0 MB → 44.9 MB (-0.1%)
investment 48.8ms ± 0.8ms 49.2ms ± 0.8ms +0.9% ✅ within noise 47.0 MB → 47.1 MB (+0.3%)
fifo 46.9ms ± 0.4ms 47.2ms ± 0.5ms +0.7% ✅ within noise 48.9 MB → 48.9 MB (-0.1%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 0.5ms, investment 0.5ms, fifo 0.3ms), and is at least 5%.
10,000 transactions per shape · 20 runs, 3 warmup · hyperfine

What do these numbers mean?
  • simple — Two-posting transfers, one currency. The historical workload — keep as the floor, not as the benchmark.
  • investment — Cost specs, per-unit prices and lot reductions. Exercises booking and inventory, which simple leaves at 0.3%.
  • fifo — Bare {} reductions against a FIFO account — how FIFO sells are normally written. The other four shapes reach the ordered-selection path twice in 2k transactions between them, so it was effectively unprofiled until it turned out to be quadratic (plan_ordered scans every lot per reduction: FIFO ledgers are quadratic (8.8s at 20k transactions) #2083).
  • vs base: the PR and the base-branch commit it is built on, built and measured in the same job
  • RSS: peak resident set size, a single sample — reported without a verdict because there is no spread to test it against
  • A shape with no beancount column is one bean-check reports errors on; it is timed for rledger only

@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 179 masked)
Full AST Match 100%
Total Files 826
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
    The headline is the EFFECTIVE rate, after pairs where beanquery
    itself is wrong are masked. raw is the same run with nothing
    masked. A widening gap means the registry grew, not that rledger
    changed.
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

… hints as they are

- CHANGELOG: the dropped file prefix on multi-file parse error messages
  moves under Breaking (rustfava unaffected; mcp-server formatErrors no
  longer names the file twice), with a Fixed bullet pointing to it.
- CHANGELOG: multi-file hints match rledger check, a LOAD error carries
  none, and validateSource still differs on E2001 (#2972); in a
  parse-error refusal, queryMultiFile/queryWithHost now report other load
  errors as LOAD, where they were code-less parse-phase errors.
- validate_with_filesystem stays pub: pub(crate) in the private api
  module trips clippy::redundant_pub_crate; say so in a comment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen robcohen changed the title fix(wasm): report multi-file errors as rledger check and the FFI do fix(wasm)!: report multi-file errors as rledger check and the FFI do Nov 13, 2026
robcohen added a commit that referenced this pull request Nov 13, 2026
WASM cache: main holds v107 (#2969), #2970 holds 108 and #2971 holds
109, so this PR moves from 106 to 110. The v107 note now says v106 was
held here and never released; loader cache stays 73.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen merged commit e7033dc into main Nov 13, 2026
67 of 68 checks passed
@robcohen
robcohen deleted the fix/wasm-multifile-errors branch November 13, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant