Skip to content

load/load-file do not report balance-assertion failures (only validate does) #1663

Closed

Description

@robcohen

Summary

ledger.load (and load-file) do not report balance assertion failures, and emit no diff on the balance directive. Only ledger.validate reports them. Embedders that load via load/load-file (rustfava does) therefore surface no error for a failing balance — the user is told their books reconcile when they don't.

Beancount's loader.load_file runs balance checking as part of loading and returns the errors; rustledger's load should match so the primary load path is safe for embedders.

Repro (v0.17.3, FFI component)

Ledger — real balance of Assets:Cash is -5 USD, but asserts 999 USD:

2024-01-01 open Assets:Cash USD
2024-01-01 open Expenses:X USD
2024-01-02 * "t"
  Expenses:X   5 USD
  Assets:Cash
2024-01-03 balance Assets:Cash   999 USD
  • load(src) → errors: [], and the returned balance directive carries no diff ({type: balance, date, account, amount: {999 USD}, tolerance: null, meta}).
  • validate(src) → correctly reports:
    { message: "Balance failed for Assets:Cash: expected 999 USD, got -5 USD", line: 6, severity: error, phase: validate }

Expected

load/load-file should:

  1. Include balance-assertion failures in errors (same as validate), so embedders that don't separately call validate still see them; and
  2. Ideally attach the computed vs asserted difference to the returned balance directive (a diff-amount/diff field), so UIs can render per-assertion pass/fail without re-deriving it.

If the load/validate split is intentional, please document that embedders must call validate for balance-check errors — but matching beancount's load-includes-balance-checks behavior is the safer default.

Impact

In rustfava this means every failing balance directive renders green/"passed" in the journal (its red/green keys off the directive diff) and produces no error banner — a silent correctness failure on the feature users rely on to catch bookkeeping mistakes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions