Skip to content

fix(loader): name the OS error once in a load error chain - #2563

Merged
robcohen merged 3 commits into
mainfrom
fix/loader-error-os-repeat
Oct 10, 2026
Merged

robcohen merged 3 commits into
mainfrom
fix/loader-error-os-repeat

Conversation

@robcohen

@robcohen robcohen commented Oct 9, 2026

Copy link
Copy Markdown
Member

What was wrong

A load failure printed through an error chain repeated the OS error:

$ rledger doctor stats /missing.beancount
error: failed to load /missing.beancount: failed to read file /missing.beancount: No such file or directory (os error 2): No such file or directory (os error 2)

and three times under rledger extract --existing as reported. Two layers each put their source in their own message and returned it from source():

  • LoadError::Io — #[error("failed to read file {path}: {source}")] with a field named source (which thiserror treats as the source).
  • ProcessError::Load — #[error("loading failed: {0}")] with #[from] (also the source).

What changed

  • LoadError::Io keeps its complete message, OS error included, and the field is renamed source → error, so the io::Error is no longer the variant's source(). Of the two ways to satisfy "source in the message or in the chain, never both", this one keeps every consumer that shows a LoadError with to_string() intact: the loader's own LOAD diagnostics (process.rs), the wasm error list, doctor. Dropping the OS error from the message instead would have silently lost it there.
  • ProcessError::Load is #[error(transparent)]: message and chain are the LoadError's.
  • Every other LoadError variant carries no source (checked; the test below enumerates them exhaustively). check.rs (JSON/plain E0001 rendering) and the wasm host FS only needed the field rename. The top-level render_error from fix(plugin): run Python plugins via __plugins__ under the host time budget #2525 is unchanged and still escapes the (now shorter) chain.

API break (CHANGELOG ### Breaking): code matching LoadError::Io { source, .. } matches error.

How tested

  • load_errors_name_each_cause_once (loader unit test): for one of every LoadError variant, alone and wrapped in ProcessError::Load, the {:#}-style chain equals the plain message, and the Io message still names the OS error.
  • test_load_failure_names_the_os_error_once (CLI): rledger doctor stats|missing-open|display-context on a missing file prints the OS error exactly once.
  • Fail-without-fix: with #[source] restored on the field and ProcessError::Load back to "loading failed: {0}", both tests fail (chain …OS-ERROR-TEXT: OS-ERROR-TEXT; doctor stats count 2).
  • cargo test -p rustledger-loader -p rustledger -p rustledger-wasm --all-features, clippy --workspace --all-features --all-targets -D warnings, cargo doc -D warnings -p rustledger-loader.

Possible follow-ups (other crates, same pattern of {0} + #[from]): rustledger-booking book.rs:46, rustledger-query error.rs:41, rustledger-plugin python/mod.rs:68,72, rustledger-importer wasm.rs:165.

Closes #2515

🤖 Generated with Claude Code

https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

LoadError::Io interpolated its io::Error into its message and also exposed
it as source(), and ProcessError::Load did the same with the whole
LoadError, so a chain printer ({e:#}) repeated the OS error two or three
times. LoadError::Io keeps a complete message (every to_string consumer
relies on it) and its field is renamed `error` so it is no longer the
source; ProcessError::Load is transparent.

Closes #2515

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 9, 2026 20:31
@codecov

codecov Bot commented Oct 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-loader/src/lib.rs 92.98% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 44.1ms ± 1.1ms 780.6ms ± 8.1ms 17.7x 51.3 MB / 50.2 MB
investment 67.3ms ± 0.3ms 2945.5ms ± 7.4ms 43.8x 57.1 MB / 58.2 MB
fifo 65.9ms ± 0.3ms 15115.9ms ± 7.1ms 229.4x 57.3 MB / 57.9 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 44.0ms ± 0.3ms 44.1ms ± 1.1ms +0.3% ✅ within noise 51.2 MB → 51.3 MB (+0.1%)
investment 67.6ms ± 0.6ms 67.3ms ± 0.3ms -0.5% ✅ within noise 56.9 MB → 57.1 MB (+0.2%)
fifo 66.3ms ± 0.5ms 65.9ms ± 0.3ms -0.6% ✅ within noise 57.3 MB → 57.3 MB (+0.0%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 0.5ms, investment 0.3ms, 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

@github-actions

github-actions Bot commented Oct 9, 2026

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

@robcohen

Copy link
Copy Markdown
Member Author

Review loop

Round Scope Checks Findings
1 Whole diff; every LoadError variant for a source; every to_string()/{e}/{e:#} display site of LoadError/ProcessError (process.rs LOAD diagnostics, wasm load_errors_to_errors, check.rs E0001, ffi-wasi helpers.rs, doctor/lint/price/extract contexts); grep for tests or callers depending on the loading failed: prefix loader/rustledger/wasm suites; fail-without-fix of both new tests; CLI on doctor stats/missing-open/display-context none

Converged after round 1. Required checks green on 5a6304396b; rustfava tests against PR component shows the known 8 failed / 671 passed.

@robcohen
robcohen merged commit 6896296 into main Oct 10, 2026
67 of 68 checks passed
@robcohen
robcohen deleted the fix/loader-error-os-repeat branch October 10, 2026 17:09
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.

Loader error repeats the OS error three times

1 participant