Skip to content

[Compat]: Highlight which transaction is erroring out #901

Closed

Description

@kudrykv

Description

There may be an error in a transaction and it doesn't balance out. In such scenario, rledger's error is unhelpful.

Beancount File

2026-04-01 open Assets:Wallet USD
2026-04-01 open Expenses:Expense

2026-04-07 * "my expense"
  Expenses:Expense                                    10 USD
  Assets:Wallet                                      -11 USD

Python Beancount Output

.../main.beancount:4: Transaction does not balance: (-1 USD)

   2026-04-07 * "my expense"
     Expenses:Expense   10 USD
     Assets:Wallet     -11 USD

Rustledger Output

main.beancount: error[E3001]: [E3001] Transaction does not balance: residual -1 USD
✗ 1 error

Python Beancount Version

3.2.0

Rustledger Version

0.13.0

Activity

  1. added
    compatibility
    on Apr 23, 2026
  2. robcohen commented on Apr 23, 2026

    @robcohen
    Member

    Confirmed, thanks. All three pieces of this are fixable and the infrastructure mostly already exists — the validation path just doesn't use it. Breakdown:

    1. Line number missing

    rustledger-loader/src/process.rs:735-753 in run_validation(): when converting ValidationError → LedgerError, the location is hardcoded to None:

    errors.push(LedgerError {
        severity: severity_level,
        code: err.code.code().to_string(),
        message: err.to_string(),
        location: None,  // <- always None
        phase: phase.to_string(),
    });

    The ValidationError already carries span and file_id. The same file has the span→line conversion a few lines above (file.line_col(spanned.span.start)). Just needs to be wired up:

    let location = err.span.and_then(|span| {
        let fid = err.file_id? as usize;
        let file = source_map.get(fid)?;
        let (line, column) = file.line_col(span.start);
        Some(ErrorLocation { file: file.path.clone(), line, column })
    });

    2. [E3001] duplicated in the message

    rustledger-validate/src/error.rs:184:

    #[error("[{code}] {message}")]
    pub struct ValidationError { ... }

    ValidationError::to_string() produces [E3001] Transaction does not balance: residual -1 USD. Then check.rs wraps it as error[E3001]: {that whole string} → duplication.

    Fix: change to #[error("{message}")]. The CLI layer always adds error[{code}]: itself.

    3. Transaction echo missing

    crates/rustledger/src/report.rs has two formatters:

    • Parse errors: use miette::GraphicalReportHandler + LabeledSpan to render source snippets with arrows/annotations (report.rs:65-100).
    • Validation errors: one-line formatter at report.rs:108-163. No snippet.

    The miette infrastructure is already there — it just isn't called for validation errors. Wiring the validation formatter to use the same path would give us Python-parity output:

    error[E3001]: Transaction does not balance: residual -1 USD
      --> main.beancount:4:1
       │
     4 │ 2026-04-07 * "my expense"
     5 │   Expenses:Expense                                    10 USD
     6 │   Assets:Wallet                                      -11 USD
       │
    

    Scope of all three fixes together is moderate — roughly a day of work — and none of it needs new crates or design. I'll put together a PR.

  3. added 4 commits that reference this issue on Apr 24, 2026
    b46700e
    d8bcae2
    04f9a2e
    4ec28e6
  4. added a commit that references this issue on Apr 24, 2026
    9b8a1c3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    compatibility

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions