From df51ffb50b441ecb72ce6948f7aa1c070a1a85a0 Mon Sep 17 00:00:00 2001 From: Adam Shannon Date: Tue, 6 Jun 2023 10:22:35 -0500 Subject: [PATCH] feat: pass through more information on length mismatch errors --- accountCreditedDrawdown.go | 4 ++-- accountDebitedDrawdown.go | 4 ++-- actualAmountPaid.go | 4 ++-- adjustment.go | 4 ++-- amountNegotiatedDiscount.go | 4 ++-- beneficiary.go | 4 ++-- beneficiaryCustomer.go | 4 ++-- beneficiaryFI.go | 4 ++-- beneficiaryIntermediaryFI.go | 4 ++-- beneficiaryReference.go | 4 ++-- businessFunctionCode.go | 4 ++-- charges.go | 4 ++-- converters.go | 19 +++++++++---------- currencyInstructedAmount.go | 4 ++-- errorWire.go | 4 ++-- exchangeRate.go | 4 ++-- fIBeneficiaryFIAdvice.go | 4 ++-- fiAdditionalFIToFI.go | 4 ++-- fiBeneficiary.go | 4 ++-- fiBeneficiaryAdvice.go | 4 ++-- fiBeneficiaryFI.go | 4 ++-- fiDrawdownDebitAccountAdvice.go | 4 ++-- fiIntermediaryFI.go | 4 ++-- fiIntermediaryFIAdvice.go | 4 ++-- fiPaymentMethodToBeneficiary.go | 4 ++-- fiReceiverFI.go | 4 ++-- fileErrors.go | 4 ++-- grossAmountRemittanceDocument.go | 4 ++-- institutionAccount.go | 4 ++-- instructedAmount.go | 4 ++-- instructingFI.go | 4 ++-- intermediaryInstitution.go | 4 ++-- localInstrument.go | 4 ++-- messageDisposition.go | 4 ++-- orderingCustomer.go | 4 ++-- orderingInstitution.go | 4 ++-- originator.go | 4 ++-- originatorFI.go | 4 ++-- originatorOptionF.go | 4 ++-- originatorToBeneficiary.go | 4 ++-- outputMessageAccountabilityData.go | 4 ++-- paymentNotification.go | 4 ++-- previousMessageIdentifier.go | 4 ++-- primaryRemittanceDocument.go | 4 ++-- receiptTimeStamp.go | 4 ++-- receiverDepositoryInstitution.go | 4 ++-- relatedRemittance.go | 4 ++-- remittance.go | 4 ++-- remittanceBeneficiary.go | 4 ++-- remittanceFreeText.go | 4 ++-- remittanceOriginator.go | 4 ++-- secondaryRemittanceDocument.go | 4 ++-- senderDepositoryInstitution.go | 4 ++-- senderReference.go | 4 ++-- senderSupplied.go | 4 ++-- senderToReceiver.go | 4 ++-- serviceMessage.go | 4 ++-- 57 files changed, 121 insertions(+), 122 deletions(-) diff --git a/accountCreditedDrawdown.go b/accountCreditedDrawdown.go index f8f4c53b..f1c80fdc 100644 --- a/accountCreditedDrawdown.go +++ b/accountCreditedDrawdown.go @@ -50,8 +50,8 @@ func (creditDD *AccountCreditedDrawdown) Parse(record string) error { creditDD.DrawdownCreditAccountNumber = value length += read - if !creditDD.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := creditDD.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/accountDebitedDrawdown.go b/accountDebitedDrawdown.go index 34f48c8b..efdd448c 100644 --- a/accountDebitedDrawdown.go +++ b/accountDebitedDrawdown.go @@ -84,8 +84,8 @@ func (debitDD *AccountDebitedDrawdown) Parse(record string) error { debitDD.Address.AddressLineThree = value length += read - if !debitDD.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := debitDD.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/actualAmountPaid.go b/actualAmountPaid.go index 765e2e11..6ac10b53 100644 --- a/actualAmountPaid.go +++ b/actualAmountPaid.go @@ -57,8 +57,8 @@ func (aap *ActualAmountPaid) Parse(record string) error { aap.RemittanceAmount.Amount = value length += read - if !aap.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := aap.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/adjustment.go b/adjustment.go index 01af64d1..3f25bc05 100644 --- a/adjustment.go +++ b/adjustment.go @@ -84,8 +84,8 @@ func (adj *Adjustment) Parse(record string) error { adj.AdditionalInfo = value length += read - if !adj.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := adj.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/amountNegotiatedDiscount.go b/amountNegotiatedDiscount.go index b7b208c0..3685c84b 100644 --- a/amountNegotiatedDiscount.go +++ b/amountNegotiatedDiscount.go @@ -57,8 +57,8 @@ func (nd *AmountNegotiatedDiscount) Parse(record string) error { nd.RemittanceAmount.Amount = value length += read - if !nd.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := nd.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/beneficiary.go b/beneficiary.go index 520ba305..323b2bbe 100644 --- a/beneficiary.go +++ b/beneficiary.go @@ -79,8 +79,8 @@ func (ben *Beneficiary) Parse(record string) error { ben.Personal.Address.AddressLineThree = value length += read - if !ben.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := ben.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/beneficiaryCustomer.go b/beneficiaryCustomer.go index 2838afd4..f440209e 100644 --- a/beneficiaryCustomer.go +++ b/beneficiaryCustomer.go @@ -85,8 +85,8 @@ func (bc *BeneficiaryCustomer) Parse(record string) error { bc.CoverPayment.SwiftLineFive = value length += read - if !bc.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := bc.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/beneficiaryFI.go b/beneficiaryFI.go index 3b9336b9..9ec782a4 100644 --- a/beneficiaryFI.go +++ b/beneficiaryFI.go @@ -79,8 +79,8 @@ func (bfi *BeneficiaryFI) Parse(record string) error { bfi.FinancialInstitution.Address.AddressLineThree = value length += read - if !bfi.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := bfi.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/beneficiaryIntermediaryFI.go b/beneficiaryIntermediaryFI.go index f827a74d..836ac743 100644 --- a/beneficiaryIntermediaryFI.go +++ b/beneficiaryIntermediaryFI.go @@ -79,8 +79,8 @@ func (bifi *BeneficiaryIntermediaryFI) Parse(record string) error { bifi.FinancialInstitution.Address.AddressLineThree = value length += read - if !bifi.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := bifi.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/beneficiaryReference.go b/beneficiaryReference.go index fc4b4997..56ee9cbf 100644 --- a/beneficiaryReference.go +++ b/beneficiaryReference.go @@ -50,8 +50,8 @@ func (br *BeneficiaryReference) Parse(record string) error { br.BeneficiaryReference = value length += read - if !br.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := br.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/businessFunctionCode.go b/businessFunctionCode.go index c001ed06..990bdb90 100644 --- a/businessFunctionCode.go +++ b/businessFunctionCode.go @@ -53,8 +53,8 @@ func (bfc *BusinessFunctionCode) Parse(record string) error { bfc.TransactionTypeCode = value length += read - if !bfc.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := bfc.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/charges.go b/charges.go index 3097dba0..f407aaac 100644 --- a/charges.go +++ b/charges.go @@ -88,8 +88,8 @@ func (c *Charges) Parse(record string) error { c.SendersChargesFour = value length += read - if !c.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := c.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/converters.go b/converters.go index d83ac201..84cf058f 100644 --- a/converters.go +++ b/converters.go @@ -5,8 +5,10 @@ package wire import ( + "fmt" "strconv" "strings" + "unicode/utf8" ) // converters handles golang to WIRE type Converters @@ -68,7 +70,6 @@ func (c *converters) formatAlphaField(s string, max uint, options FormatOptions) } func (c *converters) parseVariableStringField(r string, maxLen int) (got string, size int, err error) { - min := func(x, y int) int { if x > y { return y @@ -151,15 +152,13 @@ func (c *converters) stripDelimiters(data string) string { } // verify input data with read length -func (c *converters) verifyDataWithReadLength(data string, read int) bool { - if len(data) == read { - return true +func (c *converters) verifyDataWithReadLength(data string, expected int) error { + n := utf8.RuneCountInString(data) + if n == expected { + return nil } - - // TODO: workaround for special case, not specification - if len(data) > read && data[read:] == "*" { - return true + if n > expected && data[expected:] == "*" { + return nil } - - return false + return fmt.Errorf("found data of %d length but expected %d", n, expected) } diff --git a/currencyInstructedAmount.go b/currencyInstructedAmount.go index 644f0f63..5d47a641 100644 --- a/currencyInstructedAmount.go +++ b/currencyInstructedAmount.go @@ -60,8 +60,8 @@ func (cia *CurrencyInstructedAmount) Parse(record string) error { cia.Amount = cia.parseStringField(record[length : length+18]) length += 18 - if !cia.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := cia.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/errorWire.go b/errorWire.go index 45c22081..b542ee22 100644 --- a/errorWire.go +++ b/errorWire.go @@ -68,8 +68,8 @@ func (ew *ErrorWire) Parse(record string) error { ew.ErrorDescription = value length += read - if !ew.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := ew.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/exchangeRate.go b/exchangeRate.go index 84197ae3..f6e07faa 100644 --- a/exchangeRate.go +++ b/exchangeRate.go @@ -51,8 +51,8 @@ func (eRate *ExchangeRate) Parse(record string) error { eRate.ExchangeRate = value length += read - if !eRate.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := eRate.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/fIBeneficiaryFIAdvice.go b/fIBeneficiaryFIAdvice.go index 30d7d89f..bfbecbce 100644 --- a/fIBeneficiaryFIAdvice.go +++ b/fIBeneficiaryFIAdvice.go @@ -86,8 +86,8 @@ func (fibfia *FIBeneficiaryFIAdvice) Parse(record string) error { fibfia.Advice.LineSix = value length += read - if !fibfia.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := fibfia.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/fiAdditionalFIToFI.go b/fiAdditionalFIToFI.go index 1e0ded88..98f149da 100644 --- a/fiAdditionalFIToFI.go +++ b/fiAdditionalFIToFI.go @@ -85,8 +85,8 @@ func (fifi *FIAdditionalFIToFI) Parse(record string) error { fifi.AdditionalFIToFI.LineSix = value length += read - if !fifi.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := fifi.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/fiBeneficiary.go b/fiBeneficiary.go index 2bf5c934..6ad0e66c 100644 --- a/fiBeneficiary.go +++ b/fiBeneficiary.go @@ -85,8 +85,8 @@ func (fib *FIBeneficiary) Parse(record string) error { fib.FIToFI.LineSix = value length += read - if !fib.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := fib.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/fiBeneficiaryAdvice.go b/fiBeneficiaryAdvice.go index 86d0f8f1..505b73a7 100644 --- a/fiBeneficiaryAdvice.go +++ b/fiBeneficiaryAdvice.go @@ -86,8 +86,8 @@ func (fiba *FIBeneficiaryAdvice) Parse(record string) error { fiba.Advice.LineSix = value length += read - if !fiba.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := fiba.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/fiBeneficiaryFI.go b/fiBeneficiaryFI.go index 01e7d509..3906e8ef 100644 --- a/fiBeneficiaryFI.go +++ b/fiBeneficiaryFI.go @@ -85,8 +85,8 @@ func (fibfi *FIBeneficiaryFI) Parse(record string) error { fibfi.FIToFI.LineSix = value length += read - if !fibfi.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := fibfi.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/fiDrawdownDebitAccountAdvice.go b/fiDrawdownDebitAccountAdvice.go index 2f528e71..c734abd0 100644 --- a/fiDrawdownDebitAccountAdvice.go +++ b/fiDrawdownDebitAccountAdvice.go @@ -86,8 +86,8 @@ func (debitDDAdvice *FIDrawdownDebitAccountAdvice) Parse(record string) error { debitDDAdvice.Advice.LineSix = value length += read - if !debitDDAdvice.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := debitDDAdvice.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/fiIntermediaryFI.go b/fiIntermediaryFI.go index ab154f9e..fd2a7e2a 100644 --- a/fiIntermediaryFI.go +++ b/fiIntermediaryFI.go @@ -85,8 +85,8 @@ func (fiifi *FIIntermediaryFI) Parse(record string) error { fiifi.FIToFI.LineSix = value length += read - if !fiifi.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := fiifi.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/fiIntermediaryFIAdvice.go b/fiIntermediaryFIAdvice.go index 9395954d..2ce46b97 100644 --- a/fiIntermediaryFIAdvice.go +++ b/fiIntermediaryFIAdvice.go @@ -86,8 +86,8 @@ func (fiifia *FIIntermediaryFIAdvice) Parse(record string) error { fiifia.Advice.LineSix = value length += read - if !fiifia.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := fiifia.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/fiPaymentMethodToBeneficiary.go b/fiPaymentMethodToBeneficiary.go index ec813605..1cffc112 100644 --- a/fiPaymentMethodToBeneficiary.go +++ b/fiPaymentMethodToBeneficiary.go @@ -54,8 +54,8 @@ func (pm *FIPaymentMethodToBeneficiary) Parse(record string) error { pm.AdditionalInformation = value length += read - if !pm.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := pm.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/fiReceiverFI.go b/fiReceiverFI.go index ea08e0b2..c42c0b12 100644 --- a/fiReceiverFI.go +++ b/fiReceiverFI.go @@ -85,8 +85,8 @@ func (firfi *FIReceiverFI) Parse(record string) error { firfi.FIToFI.LineSix = value length += read - if !firfi.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := firfi.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/fileErrors.go b/fileErrors.go index 5c1d6247..8d4f99ba 100644 --- a/fileErrors.go +++ b/fileErrors.go @@ -40,9 +40,9 @@ func NewTagMinLengthErr(tagLength, length int) TagWrongLengthErr { } // NewTagMaxLengthErr creates a new error of the TagWrongLengthErr type -func NewTagMaxLengthErr() TagWrongLengthErr { +func NewTagMaxLengthErr(err error) TagWrongLengthErr { return TagWrongLengthErr{ - Message: "contains invalid information in a segment", + Message: fmt.Sprintf("invalid information in a segment: %v", err), } } diff --git a/grossAmountRemittanceDocument.go b/grossAmountRemittanceDocument.go index b3df37a2..61df294f 100644 --- a/grossAmountRemittanceDocument.go +++ b/grossAmountRemittanceDocument.go @@ -57,8 +57,8 @@ func (gard *GrossAmountRemittanceDocument) Parse(record string) error { gard.RemittanceAmount.Amount = value length += read - if !gard.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := gard.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/institutionAccount.go b/institutionAccount.go index 8416f596..f0da021c 100644 --- a/institutionAccount.go +++ b/institutionAccount.go @@ -85,8 +85,8 @@ func (iAccount *InstitutionAccount) Parse(record string) error { iAccount.CoverPayment.SwiftLineFive = value length += read - if !iAccount.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := iAccount.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/instructedAmount.go b/instructedAmount.go index d74ee079..92807e1c 100644 --- a/instructedAmount.go +++ b/instructedAmount.go @@ -60,8 +60,8 @@ func (ia *InstructedAmount) Parse(record string) error { ia.Amount = value length += read - if !ia.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := ia.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/instructingFI.go b/instructingFI.go index 551b823c..cfaa32c7 100644 --- a/instructingFI.go +++ b/instructingFI.go @@ -91,8 +91,8 @@ func (ifi *InstructingFI) Parse(record string) error { ifi.FinancialInstitution.Address.AddressLineThree = value length += read - if !ifi.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := ifi.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/intermediaryInstitution.go b/intermediaryInstitution.go index bddaf80c..83821054 100644 --- a/intermediaryInstitution.go +++ b/intermediaryInstitution.go @@ -85,8 +85,8 @@ func (ii *IntermediaryInstitution) Parse(record string) error { ii.CoverPayment.SwiftLineFive = value length += read - if !ii.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := ii.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/localInstrument.go b/localInstrument.go index 183719dc..c86f371e 100644 --- a/localInstrument.go +++ b/localInstrument.go @@ -59,8 +59,8 @@ func (li *LocalInstrument) Parse(record string) error { li.ProprietaryCode = value length += read - if !li.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := li.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/messageDisposition.go b/messageDisposition.go index c7869107..6975c7ba 100644 --- a/messageDisposition.go +++ b/messageDisposition.go @@ -80,8 +80,8 @@ func (md *MessageDisposition) Parse(record string) error { md.MessageStatusIndicator = value length += read - if !md.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := md.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/orderingCustomer.go b/orderingCustomer.go index 037ac1de..39f47609 100644 --- a/orderingCustomer.go +++ b/orderingCustomer.go @@ -85,8 +85,8 @@ func (oc *OrderingCustomer) Parse(record string) error { oc.CoverPayment.SwiftLineFive = value length += read - if !oc.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := oc.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/orderingInstitution.go b/orderingInstitution.go index c6d59431..c443512a 100644 --- a/orderingInstitution.go +++ b/orderingInstitution.go @@ -85,8 +85,8 @@ func (oi *OrderingInstitution) Parse(record string) error { oi.CoverPayment.SwiftLineFive = value length += read - if !oi.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := oi.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/originator.go b/originator.go index 53642e79..a890910b 100644 --- a/originator.go +++ b/originator.go @@ -79,8 +79,8 @@ func (o *Originator) Parse(record string) error { o.Personal.Address.AddressLineThree = value length += read - if !o.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := o.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/originatorFI.go b/originatorFI.go index 4bc7757b..4cdba66e 100644 --- a/originatorFI.go +++ b/originatorFI.go @@ -85,8 +85,8 @@ func (ofi *OriginatorFI) Parse(record string) error { ofi.FinancialInstitution.Address.AddressLineThree = value length += read - if !ofi.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := ofi.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/originatorOptionF.go b/originatorOptionF.go index 9ceea185..ba6e8fc3 100644 --- a/originatorOptionF.go +++ b/originatorOptionF.go @@ -142,8 +142,8 @@ func (oof *OriginatorOptionF) Parse(record string) error { oof.LineThree = value length += read - if !oof.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := oof.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/originatorToBeneficiary.go b/originatorToBeneficiary.go index 29c943aa..7bb1eca5 100644 --- a/originatorToBeneficiary.go +++ b/originatorToBeneficiary.go @@ -86,8 +86,8 @@ func (ob *OriginatorToBeneficiary) Parse(record string) error { ob.LineFour = value length += read - if !ob.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := ob.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/outputMessageAccountabilityData.go b/outputMessageAccountabilityData.go index e6c90e1d..e928a6cd 100644 --- a/outputMessageAccountabilityData.go +++ b/outputMessageAccountabilityData.go @@ -95,8 +95,8 @@ func (omad *OutputMessageAccountabilityData) Parse(record string) error { omad.OutputFRBApplicationIdentification = value length += read - if !omad.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := omad.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/paymentNotification.go b/paymentNotification.go index 59fdf6eb..b6387e2e 100644 --- a/paymentNotification.go +++ b/paymentNotification.go @@ -106,8 +106,8 @@ func (pn *PaymentNotification) Parse(record string) error { pn.EndToEndIdentification = value length += read - if !pn.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := pn.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/previousMessageIdentifier.go b/previousMessageIdentifier.go index ecd41286..f872303c 100644 --- a/previousMessageIdentifier.go +++ b/previousMessageIdentifier.go @@ -50,8 +50,8 @@ func (pmi *PreviousMessageIdentifier) Parse(record string) error { pmi.PreviousMessageIdentifier = value length += read - if !pmi.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := pmi.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/primaryRemittanceDocument.go b/primaryRemittanceDocument.go index 85743eae..4857cff8 100644 --- a/primaryRemittanceDocument.go +++ b/primaryRemittanceDocument.go @@ -71,8 +71,8 @@ func (prd *PrimaryRemittanceDocument) Parse(record string) error { prd.Issuer = value length += read - if !prd.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := prd.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/receiptTimeStamp.go b/receiptTimeStamp.go index 1aec0e0c..e417767b 100644 --- a/receiptTimeStamp.go +++ b/receiptTimeStamp.go @@ -68,8 +68,8 @@ func (rts *ReceiptTimeStamp) Parse(record string) error { rts.ReceiptApplicationIdentification = value length += read - if !rts.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := rts.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/receiverDepositoryInstitution.go b/receiverDepositoryInstitution.go index 916f0214..740751e1 100644 --- a/receiverDepositoryInstitution.go +++ b/receiverDepositoryInstitution.go @@ -59,8 +59,8 @@ func (rdi *ReceiverDepositoryInstitution) Parse(record string) error { rdi.ReceiverShortName = value length += read - if !rdi.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := rdi.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/relatedRemittance.go b/relatedRemittance.go index 40630107..9bbb64e6 100644 --- a/relatedRemittance.go +++ b/relatedRemittance.go @@ -189,8 +189,8 @@ func (rr *RelatedRemittance) Parse(record string) error { rr.RemittanceData.AddressLineSeven = value length += read - if !rr.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := rr.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/remittance.go b/remittance.go index 1fa36335..f635f333 100644 --- a/remittance.go +++ b/remittance.go @@ -78,8 +78,8 @@ func (ri *Remittance) Parse(record string) error { ri.CoverPayment.SwiftLineFour = value length += read - if !ri.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := ri.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/remittanceBeneficiary.go b/remittanceBeneficiary.go index 3ae60587..0433cc18 100644 --- a/remittanceBeneficiary.go +++ b/remittanceBeneficiary.go @@ -212,8 +212,8 @@ func (rb *RemittanceBeneficiary) Parse(record string) error { rb.RemittanceData.CountryOfResidence = value length += read - if !rb.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := rb.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/remittanceFreeText.go b/remittanceFreeText.go index c6c6ed43..c68065c7 100644 --- a/remittanceFreeText.go +++ b/remittanceFreeText.go @@ -68,8 +68,8 @@ func (rft *RemittanceFreeText) Parse(record string) error { rft.LineThree = value length += read - if !rft.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := rft.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/remittanceOriginator.go b/remittanceOriginator.go index dc69a2e9..baaa479d 100644 --- a/remittanceOriginator.go +++ b/remittanceOriginator.go @@ -266,8 +266,8 @@ func (ro *RemittanceOriginator) Parse(record string) error { ro.ContactOther = value length += read - if !ro.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := ro.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/secondaryRemittanceDocument.go b/secondaryRemittanceDocument.go index dc433bdc..2126ecc7 100644 --- a/secondaryRemittanceDocument.go +++ b/secondaryRemittanceDocument.go @@ -77,8 +77,8 @@ func (srd *SecondaryRemittanceDocument) Parse(record string) error { srd.Issuer = value length += read - if !srd.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := srd.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/senderDepositoryInstitution.go b/senderDepositoryInstitution.go index 462e7919..89e7a8b6 100644 --- a/senderDepositoryInstitution.go +++ b/senderDepositoryInstitution.go @@ -59,8 +59,8 @@ func (sdi *SenderDepositoryInstitution) Parse(record string) error { sdi.SenderShortName = value length += read - if !sdi.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := sdi.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/senderReference.go b/senderReference.go index d3e9b6be..6ba4086f 100644 --- a/senderReference.go +++ b/senderReference.go @@ -50,8 +50,8 @@ func (sr *SenderReference) Parse(record string) error { sr.SenderReference = value length += read - if !sr.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := sr.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/senderSupplied.go b/senderSupplied.go index 5e276e13..257386ff 100644 --- a/senderSupplied.go +++ b/senderSupplied.go @@ -70,8 +70,8 @@ func (ss *SenderSupplied) Parse(record string) error { ss.MessageDuplicationCode = ss.parseAlphaField(record[length:], 1) length += 1 - if !ss.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := ss.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/senderToReceiver.go b/senderToReceiver.go index 408101d5..770f563e 100644 --- a/senderToReceiver.go +++ b/senderToReceiver.go @@ -92,8 +92,8 @@ func (str *SenderToReceiver) Parse(record string) error { str.CoverPayment.SwiftLineSix = value length += read - if !str.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := str.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil diff --git a/serviceMessage.go b/serviceMessage.go index 6dfa7f0e..b805171a 100644 --- a/serviceMessage.go +++ b/serviceMessage.go @@ -149,8 +149,8 @@ func (sm *ServiceMessage) Parse(record string) error { sm.LineTwelve = value length += read - if !sm.verifyDataWithReadLength(record, length) { - return NewTagMaxLengthErr() + if err := sm.verifyDataWithReadLength(record, length); err != nil { + return NewTagMaxLengthErr(err) } return nil