--- a/internal/ledger/apply.go 2026-03-02 09:14:03.000000000 +0000 +++ b/internal/ledger/apply.go 2026-03-02 10:41:55.000000000 +0000 @@ -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 }