From 9681a710cdf5ea477cbe88387f9ebcffa0caf214 Mon Sep 17 00:00:00 2001 From: Shane Huston Date: Wed, 13 Oct 2021 17:33:40 +0100 Subject: [PATCH] Improve error messages for transactions All error messages for transactions now include the raw data for easier debugging --- transactions/aibTransaction.go | 8 ++++---- transactions/revolutTransaction.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/transactions/aibTransaction.go b/transactions/aibTransaction.go index 142c195..387deeb 100644 --- a/transactions/aibTransaction.go +++ b/transactions/aibTransaction.go @@ -29,7 +29,7 @@ func NewAIBTransaction(rawData string) *aibTransaction { transactionDate, err := time.Parse("02/01/06", data[1]) if err != nil { - log.Fatal("Could not parse date: ", err) + log.Fatal("Could not parse date: ", err, "\nRaw data: ", rawData) } t.completedDate = transactionDate @@ -39,7 +39,7 @@ func NewAIBTransaction(rawData string) *aibTransaction { t.amount, err = t.parseAmount(data[3], data[4]) if err != nil { - log.Fatal("Could not parse amount: ", err) + log.Fatal("Could not parse amount: ", err, "\nRaw data: ", rawData) } t.balance = data[5] @@ -80,7 +80,7 @@ func (t aibTransaction) parseAmount(debitAmount string, creditAmount string) (fl amount, err := strconv.ParseFloat(debitAmount, 32) if err != nil { - log.Fatal("Could not parse amount: ", err) + return amount, fmt.Errorf("Could not parse amount: %w", err) } return amount, nil @@ -90,7 +90,7 @@ func (t aibTransaction) parseAmount(debitAmount string, creditAmount string) (fl amount, err := strconv.ParseFloat(creditAmount, 32) if err != nil { - log.Fatal("Could not parse amount: ", err) + return amount, fmt.Errorf("Could not parse amount: %w") } if amount != 0 { diff --git a/transactions/revolutTransaction.go b/transactions/revolutTransaction.go index ddfd26c..18dec03 100644 --- a/transactions/revolutTransaction.go +++ b/transactions/revolutTransaction.go @@ -34,7 +34,7 @@ func NewRevolutTransaction(rawData string) *revolutTransaction { completedDate, err := time.Parse("2 Jan 2006", data[0]) if err != nil { - log.Fatal("Could not parse date: ", err) + log.Fatal("Could not parse date: ", err, "\nRaw data: ", rawData) } t.completedDate = completedDate @@ -46,7 +46,7 @@ func NewRevolutTransaction(rawData string) *revolutTransaction { if paidOut != "" { t.amount, err = strconv.ParseFloat(paidOut, 64) if err != nil { - log.Fatal("Could not parse amount: ", err, "\nRaw data: ", rawData) + log.Fatal("Could not parse date: ", err, "\nRaw data: ", rawData) } } else { t.amount, err = strconv.ParseFloat(paidIn, 32)