From cdbd7c648caa53322292d5709d478c2c3caaa38e Mon Sep 17 00:00:00 2001 From: Ada Fernsby Date: Mon, 2 Mar 2026 09:14:03 +0000 Subject: [PATCH 1/3] feat(ledger): treat a zero delta as a no-op In-Reply-To: <024f75262757878b20f7a3e64c1472d87a75d6b8.1772442000.git.ada.fernsby@example.invalid> References: <024f75262757878b20f7a3e64c1472d87a75d6b8.1772442000.git.ada.fernsby@example.invalid> Apply returned a wrapped error for zero-value postings, which the reconciliation job counted as a failure. Signed-off-by: Ada Fernsby --- internal/ledger/apply.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/internal/ledger/apply.go b/internal/ledger/apply.go index 95f499d..ce501c6 100644 --- a/internal/ledger/apply.go +++ b/internal/ledger/apply.go @@ -1,14 +1,21 @@ package ledger -import "errors" +import ( + "errors" + "fmt" +) // ErrShortBalance is returned when a posting would drive the balance negative. var ErrShortBalance = errors.New("ledger: insufficient balance") // Apply posts one delta against the running balance and returns the new total. +// A zero delta is a no-op and never reports an error. func Apply(balance, delta int64) (int64, error) { + if delta == 0 { + return balance, nil + } if balance+delta < 0 { - return balance, ErrShortBalance + return balance, fmt.Errorf("%w: balance %d, requested %d", ErrShortBalance, balance, delta) } return balance + delta, nil } -- 2.43.0