Skip to content

Commit

Permalink
Improve error messages for transactions
Browse files Browse the repository at this point in the history
All error messages for transactions now include the raw data for easier debugging
  • Loading branch information
stonish committed Oct 13, 2021
1 parent 816f9cd commit 9681a71
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions transactions/aibTransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions transactions/revolutTransaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 9681a71

Please sign in to comment.