Repository navigation
fix: restore "not enough" phrasing for InsufficientUnits booking error - #749
Merged
Merged
Conversation
PR #745 made the booking layer propagate `InsufficientUnits` errors directly to the user instead of letting them be silently swallowed and re-emitted by the validator. That was the right architectural move, but the booking variant's Display string ("insufficient units: need X but only Y available") differed from the validator's pre-existing phrasing ("Not enough units in <account>: requested X, available Y; not enough to reduce"), and the conformance suite (and downstream user tooling) matches on "not enough". Result: pta-standards `reduction-exceeds-inventory` regressed from passing to failing on the error_contains assertion, even though the error itself is still correctly detected. Align the booking layer's Display to match the validator's wording verbatim. The `account` field is already on the variant (added in #745 for exactly this purpose), so no struct change is needed. Add a regression test that pins the Display string against the three assertions that matter: contains "not enough", contains the account name, contains both numbers. The test references #748 in its docstring so the next person to touch the variant understands why the exact phrasing is load-bearing. Closes #748 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Restores the beancount/validator-compatible “not enough” phrasing for BookingError::InsufficientUnits in rustledger-booking, fixing a pta-standards conformance regression introduced when booking errors began propagating directly to users.
Changes:
- Update
BookingError::InsufficientUnits’sDisplaystring to match the validator’s existing “Not enough units in …; not enough to reduce” wording (including the account name). - Add documentation explaining why the exact phrasing is load-bearing for conformance/tooling.
- Add a regression test asserting the rendered error contains “not enough”, the account name, and requested/available numbers.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
robcohen
enabled auto-merge
April 11, 2026 01:34
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs main branch (2026-04-10)
What do these numbers mean?
|
6 tasks
Member
Author
robcohen
added this pull request to the merge queue
Apr 11, 2026
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
robcohen
added a commit
that referenced
this pull request
Apr 11, 2026
Before this change, the same logical failure ("reduction exceeds
available inventory") was encoded as three separate error types with
three separate hand-written Display strings across three crates:
- `rustledger_core::BookingError` — inventory-level, no account
- `rustledger_booking::BookingError` — wraps core, adds account
- `rustledger_validate::ValidationError` — hand-formatted from core
Twelve match arms across three crates all encoded the same 4-way
structure (`InsufficientUnits`, `NoMatchingLot`, `AmbiguousMatch`,
`CurrencyMismatch`), and the three Display strings drifted apart —
that was the root cause of #748, where the booking layer's "insufficient
units: need X but only Y available" bypassed the validator's "Not enough
units in ..." and dropped the phrasing the pta-standards conformance
suite asserts on.
This commit unifies the user-facing wording into a single
`rustledger_core::AccountedBookingError { error, account }` type with
one canonical `Display` impl per variant, constructed via
`BookingError::with_account(self, account)`:
- `rustledger-core`: add `AccountedBookingError` struct + Display +
`BookingError::with_account` constructor. The raw `BookingError`
still exists for `Inventory::reduce` (which doesn't know its own
account), but every user-facing rendering goes through the new type.
- `rustledger-booking`: collapse `BookingError::{InsufficientUnits,
NoMatchingLot, AmbiguousMatch}` (3 variants) into a single
`BookingError::Inventory(AccountedBookingError)` variant with
transparent Display. `convert_core_booking_error` becomes a
one-liner: `BookingError::Inventory(err.with_account(account))`.
- `rustledger-validate`: stop hand-formatting inventory errors.
Each match arm now calls `format!("{}", err.with_account(...))`
and assigns the appropriate `ErrorCode`. ~15 lines of hand-rolled
format strings deleted.
- `rustledger`: `cmd/check.rs` `code_for` now dispatches on the
inner `core::BookingError` variant of the unified
`BookingError::Inventory` arm.
Net: 8 of 12 match arms eliminated, and no independent Display strings
remain that can drift apart. Adding a fifth booking failure variant
now means touching one crate, not three.
The #748 regression test from #749 still passes unchanged (it exercises
the new path via `BookingError::Inventory(core_err.with_account(...))`,
which is the same code path `rledger check` and the validator now use).
Canonical Display strings (locked by the test and by pta-standards):
- InsufficientUnits: "Not enough units in {account}: requested {req},
available {avail}; not enough to reduce"
- NoMatchingLot: "No matching lot for {currency} in {account}"
- AmbiguousMatch: "Ambiguous lot match for {currency}: {n} lots
match in {account}"
- CurrencyMismatch: "Currency mismatch in {account}: expected {e},
got {g}"
Closes #750
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
robcohen
added a commit
that referenced
this pull request
Apr 11, 2026
Before this change, the same logical failure ("reduction exceeds
available inventory") was encoded as three separate error types with
three separate hand-written Display strings across three crates:
- `rustledger_core::BookingError` — inventory-level, no account
- `rustledger_booking::BookingError` — wraps core, adds account
- `rustledger_validate::ValidationError` — hand-formatted from core
Twelve match arms across three crates all encoded the same 4-way
structure (`InsufficientUnits`, `NoMatchingLot`, `AmbiguousMatch`,
`CurrencyMismatch`), and the three Display strings drifted apart —
that was the root cause of #748, where the booking layer's "insufficient
units: need X but only Y available" bypassed the validator's "Not enough
units in ..." and dropped the phrasing the pta-standards conformance
suite asserts on.
This commit unifies the user-facing wording into a single
`rustledger_core::AccountedBookingError { error, account }` type with
one canonical `Display` impl per variant, constructed via
`BookingError::with_account(self, account)`:
- `rustledger-core`: add `AccountedBookingError` struct + Display +
`BookingError::with_account` constructor. The raw `BookingError`
still exists for `Inventory::reduce` (which doesn't know its own
account), but every user-facing rendering goes through the new type.
- `rustledger-booking`: collapse `BookingError::{InsufficientUnits,
NoMatchingLot, AmbiguousMatch}` (3 variants) into a single
`BookingError::Inventory(AccountedBookingError)` variant with
transparent Display. `convert_core_booking_error` becomes a
one-liner: `BookingError::Inventory(err.with_account(account))`.
- `rustledger-validate`: stop hand-formatting inventory errors.
Each match arm now calls `format!("{}", err.with_account(...))`
and assigns the appropriate `ErrorCode`. ~15 lines of hand-rolled
format strings deleted.
- `rustledger`: `cmd/check.rs` `code_for` now dispatches on the
inner `core::BookingError` variant of the unified
`BookingError::Inventory` arm.
Net: 8 of 12 match arms eliminated, and no independent Display strings
remain that can drift apart. Adding a fifth booking failure variant
now means touching one crate, not three.
The #748 regression test from #749 still passes unchanged (it exercises
the new path via `BookingError::Inventory(core_err.with_account(...))`,
which is the same code path `rledger check` and the validator now use).
Canonical Display strings (locked by the test and by pta-standards):
- InsufficientUnits: "Not enough units in {account}: requested {req},
available {avail}; not enough to reduce"
- NoMatchingLot: "No matching lot for {currency} in {account}"
- AmbiguousMatch: "Ambiguous lot match for {currency}: {n} lots
match in {account}"
- CurrencyMismatch: "Currency mismatch in {account}: expected {e},
got {g}"
Closes #750
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
This was referenced Apr 11, 2026
robcohen
added a commit
that referenced
this pull request
Apr 11, 2026
Bumps the whole workspace from 0.11.0 to 0.12.0 (minor version bump under pre-1.0 semver because the cycle since 0.11.0 includes user-visible breaking changes that release-plz's auto-detection missed). release-plz auto-generated a v0.11.1 patch bump from the `fix:` / `feat:` commits since 0.11.0. That's too conservative. The cycle since 0.11.0 shipped the following breaking changes, all merged as `refactor:` / `fix:` without the `!` conventional-commit marker: - **`rustledger_booking::BookingError`** collapsed three variants (`InsufficientUnits`, `NoMatchingLot`, `AmbiguousMatch`) into a single `Inventory(AccountedBookingError)` variant (#751). Out-of-tree consumers pattern-matching on the old variants break. - **`rustledger_core::AccountedBookingError`** added as a new canonical user-facing type with `BookingError::with_account()` as the constructor (#751). Not a break on its own, but part of the unification. - **`rustledger_lsp::handlers::diagnostics::all_diagnostics`** signature changed to take an additional `other_buffer_overlays: &[(u16, &[Spanned<Directive>])]` parameter for multi-buffer LSP overlays (#760 / #764). - **`rustledger_lsp::handlers::diagnostics::validation_errors_to_diagnostics`** signature changed to take an owned `Vec<Spanned<Directive>>` instead of borrowed slices (#758). Optimizes a hot path but breaks the function's public signature. - **`rustledger_loader::LoadError::IncludeCycle`** Display format rewritten to match Python beancount's `"Duplicate filename parsed: ..."` wording (#767). Substring-matching consumers break. Under pre-1.0 semver, any breaking change should bump the minor version (0.x → 0.(x+1)). So 0.11.0 → 0.12.0 is correct. Highlights since 0.11.0: ### Breaking - Unified `BookingError` under a single `Inventory` variant with one canonical `Display` impl, preventing the wording drift that produced #748 (#751). - `LoadError::IncludeCycle` Display now begins with `"Duplicate filename parsed: "` to match beancount's wording for conformance (#767). - LSP `all_diagnostics` and `validation_errors_to_diagnostics` signatures changed to support the multi-buffer overlay and avoid double-cloning directive lists (#758 / #764). ### Features - LSP live overlay so in-memory buffer edits reflect in diagnostics before save, for both the current file (#685 / #758) and any other open buffer in a multi-file ledger (#760 / #764). - Parser `Vec::with_capacity` hints with DoS caps on `source.len()` heuristics (#754). - `working_inventories` cloning in the booking engine now only touches accounts actually referenced in the transaction, and dedupes repeated account references (#756). ### Fixes - `InsufficientUnits` booking error wording restored to `"Not enough units in ..."` so pta-standards `reduction-exceeds-inventory` conformance assertion passes (#748 / #749). - `noduplicates` plugin now hashes flag, tags, links, cost, and price in addition to date and narration — complete beancount `hash_entry` parity (#746 / #747). - Parser test suite: 14 fake-coverage tests replaced with real tests that exercise the functions they claim to cover (#766). - All Copilot inline review comments on #754-#763, #766, #767 addressed in fix commits. - Closed PRs #768 (dead incremental parser) and #769 (hallucinated simdutf8 API) — no code shipped from these. ### Internal - Forbid-unsafe-code invariant now has a dedicated CI check and pre-push hook (#770). - New pre-push `cargo check` hook to catch compile errors before PRs are opened (#770). This commit supersedes release-plz's auto-generated v0.11.1 proposal to produce the minor bump the breaking changes require. Co-Authored-By: Claude Opus 4.6 (1M context) <[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.
Summary
Fixes the pta-standards
reduction-exceeds-inventoryconformance regression introduced by #745.PR #745 made the booking layer propagate
BookingError::InsufficientUnitsdirectly to the user instead of letting the validator's "Not enough units in ..." message win. The booking variant's Display string ("insufficient units: need X but only Y available") didn't contain "not enough", and the conformance test asserts onerror_contains: ["not enough"]. The error itself is still correctly detected — only the wording diverged.This PR aligns the booking layer's
#[error(...)]to the validator's pre-existing phrasing verbatim. Theaccountfield is already on the variant (added in #745 for exactly this purpose), so no struct change is needed.Before:
After:
Why option 1, not the bigger refactor
#748 outlined two fixes:
InsufficientUnitstype betweenrustledger-bookingandrustledger-validate.Option 2 is the right longer-term cleanup, but it's invasive and out of scope for a regression fix. Option 1 is one-line and pins behavior with a regression test. Option 2 should get its own tracking issue once this lands.
Regression test
Added
test_insufficient_units_display_contains_not_enoughincrates/rustledger-booking/src/book.rs. Asserts the rendered Display string contains:"not enough"(the conformance assertion)The test docstring references #748 so the next person to touch the variant understands why the exact phrasing is load-bearing. A doc comment on the
InsufficientUnitsvariant itself also explains the constraint.Test plan
cargo test -p rustledger-booking— all 76 tests pass (75 existing + 1 new)cargo test --workspace --all-features— full suite greencargo clippy --all-features --all-targets -- -D warnings— cleancargo fmt --all -- --check— cleanreduction-exceeds-inventoryflips back to passing once this landsCloses #748