From 4e831d94db8a442c9f385c1b1e0553f4d31a3c9b Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Mon, 6 Nov 2023 13:18:02 +0100 Subject: [PATCH] Avoid panic error when there is no expense to compute the sum of --- pkg/expenses.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/expenses.go b/pkg/expenses.go index 06360a5..b5d9423 100644 --- a/pkg/expenses.go +++ b/pkg/expenses.go @@ -158,8 +158,9 @@ func (page *expensesIndexPage) mustComputeExpensesTotalAmount(ctx context.Contex join currency using (currency_code) group by decimal_digits `, where), args...) - if err := row.Scan(&page.SumAmount, &page.SumTotal); err != nil { - panic(err) + if notFoundErrorOrPanic(row.Scan(&page.SumAmount, &page.SumTotal)) { + page.SumAmount = "0.0" + page.SumTotal = "0.0" } row = conn.QueryRow(ctx, fmt.Sprintf(` @@ -180,8 +181,8 @@ func (page *expensesIndexPage) mustComputeExpensesTotalAmount(ctx context.Contex group by decimal_digits `, where), args...) var taxes [][]string - if err := row.Scan(&taxes); err != nil { - panic(err) + if notFoundErrorOrPanic(row.Scan(&taxes)) { + // well, nothing to do } page.SumTaxes = make(map[string]string) for _, tax := range taxes {