From 61490f2b8ca2fcea948781ef5546ad90f5baa2ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=C3=AFs_Lef=C3=A8vre?= Date: Tue, 10 Mar 2026 13:22:41 +0100 Subject: [PATCH] =?UTF-8?q?fix=28rounding=29=3A_d=C3=A9tecter_les_?= =?UTF-8?q?arrondis_n=C3=A9gatifs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Les montants négatifs étaient arrondis vers zéro. The commit body is UTF-8 8-bit while the headers are RFC 2047 encoded words. --- 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