From 3d84740a058be6f6e9484e7c9da1781a6b7bd719 Mon Sep 17 00:00:00 2001 From: Martin Habbecke Date: Sun, 17 Oct 2021 12:21:46 -0700 Subject: [PATCH] cmd/ofx: check for nil Currency fields in transactions --- cmd/ofx/banktransactions.go | 2 +- cmd/ofx/cctransactions.go | 2 +- common.go | 6 +----- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/cmd/ofx/banktransactions.go b/cmd/ofx/banktransactions.go index 5bb7e6e..3ce0ddb 100644 --- a/cmd/ofx/banktransactions.go +++ b/cmd/ofx/banktransactions.go @@ -77,7 +77,7 @@ func bankTransactions() { func printTransaction(defCurrency ofxgo.CurrSymbol, tran *ofxgo.Transaction) { currency := defCurrency - if ok, _ := tran.Currency.Valid(); ok { + if tran.Currency != nil { currency = tran.Currency.CurSym } diff --git a/cmd/ofx/cctransactions.go b/cmd/ofx/cctransactions.go index 3756bfe..6f989a3 100644 --- a/cmd/ofx/cctransactions.go +++ b/cmd/ofx/cctransactions.go @@ -60,7 +60,7 @@ func ccTransactions() { fmt.Println("Transactions:") for _, tran := range stmt.BankTranList.Transactions { currency := stmt.CurDef - if ok, _ := tran.Currency.Valid(); ok { + if tran.Currency != nil { currency = tran.Currency.CurSym } diff --git a/common.go b/common.go index dc173ac..bfbaeb3 100644 --- a/common.go +++ b/common.go @@ -362,11 +362,7 @@ type Currency struct { } // Valid returns whether the Currency is valid according to the OFX spec -func (c *Currency) Valid() (bool, error) { - if c == nil { - return false, errors.New("Currency is nil") - } - +func (c Currency) Valid() (bool, error) { if c.CurRate.IsInt() && c.CurRate.Num().Int64() == 0 { return false, errors.New("CurRate may not be zero") } else if ok, err := c.CurSym.Valid(); !ok {