Skip to content

fix: name each underlying error once in booking, query, plugin and importer error chains - #2617

Merged
robcohen merged 1 commit into
mainfrom
fix/error-chain-duplicate-cause
Oct 12, 2026
Merged

robcohen merged 1 commit into
mainfrom
fix/error-chain-duplicate-cause

Conversation

@robcohen

Copy link
Copy Markdown
Member

What was wrong

This is the same bug as #2515, fixed for the loader in #2563. An error type put its cause in its own message and returned it from source(), so any {:#} / chain rendering printed the cause twice. rledger's render_error is one such renderer, as is anyhow's alternate format.

What changed

The fix follows #2563: keep the complete message and drop the duplicate from the chain. That keeps every to_string() consumer's text, which #[error(transparent)] would not.

Crate Variant(s) Change
booking BookingError::Interpolation (book.rs:46) no longer #[from]; hand-written From<InterpolationError>
query QueryError::Parse (error.rs:41) no longer #[from]; hand-written From<ParseError>
plugin PythonError::Io, PythonError::Wasm (python/mod.rs:68,72) no longer #[from]; hand-written Froms. Wasm now prints {0:#}, so the wasmtime::Error's inner causes, which only the chain carried, stay in the message.
plugin ConversionError::BookedCostInvariantViolated (convert/mod.rs:45, same pattern, not in the issue) no longer #[from]; hand-written From
importer WasmImporterError: Encode (wasm.rs:165) and every other variant with the same pattern (Io, DirEntry, Compile, Runtime, Decode, ExportSignatureMismatch) tuple variants lose #[source]. Struct variants rename the field source → error, because thiserror makes a field named source the source. ExportSignatureMismatch prints {error:#}, like Compile and Runtime already did.

render_error (#2525) is unchanged and still escapes the whole chain, which is now just the message. The importer variants that quote module text still escape it in their own message.

API break (CHANGELOG ### Breaking): code matching WasmImporterError::{Io, DirEntry, Compile, ExportSignatureMismatch} { source, .. } must use error. Every From impl is kept, so ? works as before.

How tested

One test per site, each asserting that the {:#}-style chain equals the plain message and that the inner text appears once:

  • interpolation_error_names_its_cause_once_2574 (booking)
  • parse_error_names_its_cause_once_2574 (query)
  • io_and_wasm_errors_name_their_cause_once_2574 (plugin; also checks that Wasm prints OUTER: INNER)
  • booked_cost_invariant_error_names_its_cause_once_2574 (plugin)
  • wasm_importer_errors_name_each_cause_once_2574 (importer). It builds one of every WasmImporterError variant behind an exhaustive match, so a variant added later must be added to the test. It also checks that every message still carries its cause, and the whole chain for an anyhow cause.

Fail without the fix: with #[source] put back on each changed field (keeping the hand-written Froms), all 5 tests fail.

Checks run:

  • cargo test --all-features for rustledger-booking, -query, -plugin and -importer: 1862 passed, 0 failed.
  • cargo test -p rustledger --all-features: 1014 passed, plus one failure, host_time_budget_applies_to_python_plugins. It hit its wall-clock deadline on a machine at load average ~70, and passed 7/7 on rerun. That path uses PythonError::Execution, which this PR does not touch.
  • cargo clippy --workspace --all-features --all-targets -D warnings is clean, and so is the release-configuration clippy.
  • RUSTDOCFLAGS=-D warnings cargo doc is clean for each changed crate.

Closes #2574

🤖 Generated with Claude Code

https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

…porter error chains

Same bug as #2515: an error that interpolated its cause into its own
message and also returned it from source() printed the cause twice in a
{:#} chain. BookingError::Interpolation, QueryError::Parse, PythonError::Io
and ::Wasm, ConversionError::BookedCostInvariantViolated and seven
WasmImporterError variants keep their complete message and no longer
chain the cause; From impls are written by hand (#[from] implies
#[source]). anyhow causes print with {:#} so their own chain stays in
the message. WasmImporterError's `source` fields are renamed `error`
(thiserror treats a field named `source` as the source).

Closes #2574

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
@robcohen
robcohen requested a review from a team as a code owner October 11, 2026 17:39
@github-actions

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 45.8ms ± 1.0ms 820.5ms ± 4.6ms 17.9x 51.1 MB / 50.1 MB
investment 70.6ms ± 1.2ms 3007.9ms ± 18.0ms 42.6x 57.3 MB / 58.2 MB
fifo 70.5ms ± 0.8ms 15346.9ms ± 162.7ms 217.6x 57.3 MB / 57.8 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 44.8ms ± 0.4ms 45.8ms ± 1.0ms +2.2% ✅ within noise 51.1 MB → 51.1 MB (-0.0%)
investment 69.9ms ± 0.7ms 70.6ms ± 1.2ms +1.0% ✅ within noise 57.3 MB → 57.3 MB (-0.1%)
fifo 70.5ms ± 0.8ms 70.5ms ± 0.8ms +0.0% ✅ within noise 57.2 MB → 57.3 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.6ms, fifo 0.5ms), 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

@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 819
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

@codecov

codecov Bot commented Oct 11, 2026

Copy link
Copy Markdown

@robcohen

Copy link
Copy Markdown
Member Author

Review loop

Round Scope Finding Fix
1 Every #[from] / #[source] / field named source in booking, query, plugin and importer Found the same pattern in ConversionError::BookedCostInvariantViolated and six more WasmImporterError variants beyond the issue's four sites included in the PR, each covered by a test
2 Production consumers of .source(), .chain() or downcast_ref on these types: none (the only chain() is the pager's broken-pipe check on its own io::Error). PythonError::Wasm with {0:#} against the dispatch's {e} rendering. CLI suite: host_time_budget_applies_to_python_plugins failed once at load ~70, on its wall-clock deadline in the untouched Execution path, and passed 7/7 on rerun. none n/a

Required checks are green on 5b1477cc. Slim Build is red for main's sccache reason (#2606). The release-config clippy is clean locally. rustfava: 8/671, expected.

@robcohen
robcohen merged commit 45e817e into main Oct 12, 2026
64 of 67 checks passed
@robcohen
robcohen deleted the fix/error-chain-duplicate-cause branch October 12, 2026 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Four more error types print their underlying error twice (same as #2515)

1 participant