Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change TraceNumber and OriginalTrace to strings to prevent errors #366

Closed
adamdecaf opened this issue Nov 9, 2018 · 16 comments
Closed

Change TraceNumber and OriginalTrace to strings to prevent errors #366

adamdecaf opened this issue Nov 9, 2018 · 16 comments
Assignees
Labels

Comments

@adamdecaf
Copy link
Member

adamdecaf commented Nov 9, 2018

(The original issue was #236.)

TraceNumber (and likely other fields) have known edge cases and bugs.

We should change this type to be a string (perhaps a TraceNumber type) to prevent both bugs. This is a breaking change however, so we should release it sooner rather than later.

We should also scan the other fields (int types) for similar problems.

@adamdecaf adamdecaf self-assigned this Nov 9, 2018
@adamdecaf adamdecaf added the bug label Nov 9, 2018
adamdecaf added a commit to adamdecaf/ach that referenced this issue Nov 9, 2018
@adamdecaf
Copy link
Member Author

adamdecaf commented Nov 9, 2018

For reference, here's all other int types aside from TraceNumber and OriginalTrace:

	AddendaRecordIndicator             int // 0 or 1
	AddendaRecords                     int // count 
	Amount                             int // non-negative int
	BatchCount                         int // count
	BatchNumber                        int // count 
	BlockCount                         int // count 
	EntryAddendaCount                  int // count 
	EntryDetailSequenceNumber          int // non-negative int
	EntryHash                          int // sum of ABA's 
	ForeignExchangeReferenceIndicator  int // fixed set of values (0, 1, 2)
	ForeignPaymentAmount               int // non-negative int
	OriginatorStatusCode               int // fixed set of values (0, 1, 2)
	SequenceNumber                     int // non-negative int
	ServiceClassCode                   int // fixed set of values
	TotalCreditEntryDollarAmountInFile int // sum
	TotalDebitEntryDollarAmountInFile  int // sum 
	TransactionCode                    int // fixed set of values

@adamdecaf
Copy link
Member Author

Going by that table I don't think we need to change any other values. Double checking with @bkmoovio and @wadearnold

@adamdecaf adamdecaf changed the title Change TraceNumber (and other int types) to strings to prevent errors Change TraceNumber and OriginalTrace to strings to prevent errors Nov 9, 2018
@bkmoovio
Copy link
Contributor

bkmoovio commented Nov 9, 2018

Remind me why we are doing this again? If I recall you were running a 32 bit system? Didn’t you put a check in that says we don’t support 32 bit systems? Just trying to remember the issue?

@adamdecaf
Copy link
Member Author

Yes, but the 32bit issue was a problem of overflow.

There's still the problem of any integer type truncating leading 0's from routing numbers.

@bkmoovio
Copy link
Contributor

bkmoovio commented Nov 9, 2018

Which routing numbers are not string?

@adamdecaf
Copy link
Member Author

TraceNumber (and OriginalTrace) have routing numbers as their prefix.

@bkmoovio
Copy link
Contributor

bkmoovio commented Nov 9, 2018

Why hasn't it been an issue? Sorry just trying to understand that? I'm just wondering if you are fixing something that may never be an issue? Or is it that we just have had a routing number with leading 0?

@bkmoovio
Copy link
Contributor

bkmoovio commented Nov 9, 2018

I just changed the PPD file write to have routing numbers with leading zero's. There were no errors. Apologies. I'm sure there is an issue, but I'm just not seeing it.

101 031380104 0210428821811090000A094101Federal Reserve Bank My Bank Name
5220Name on Account 021042882 PPDREG.SALARY 181110 0121042880000001
62223138010412345678 0100000000 Receiver Account Name 0121042880000001
82200000010023138010000000000000000100000000021042882 121042880000001
9000001000001000000010023138010000000000000000100000000
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999

@adamdecaf
Copy link
Member Author

I see a few problems, but maybe we can suggest TraceNumberField().

The following are all invalid, but could be written by accident.

  • string(ed.TraceNumber)[:9] will often panic (ed.TraceNumber is converted to a UTF-8 codepoint)
  • fmt.Sprintf("%d", ed.TraceNumber)[:9] is also invalid for leading-zero routing numbers. (The 0 is missing.)

@bkmoovio
Copy link
Contributor

bkmoovio commented Nov 9, 2018

The underlying library uses TraceNumberField(), right?

@bkmoovio
Copy link
Contributor

bkmoovio commented Nov 9, 2018

// TraceNumberField returns a zero padded TraceNumber string
func (ed *EntryDetail) TraceNumberField() string {
return ed.numericField(ed.TraceNumber, 15)
}

@adamdecaf
Copy link
Member Author

adamdecaf commented Nov 13, 2018

I was thinking about this over the weekend. What if we un-export TraceNumber and use the unexported value to store what's in a file we read, but otherwise concat the two values which comprise it?

   traceNumber string
// ... later on

// returns either traceNumber (if non-empty) or concat the strings
func (..) TraceNumberField() string {

}

Doing so breaks an implicit 1:1 mapping we have from "ACH field" to "struct field".

@wadearnold
Copy link
Member

Consumers of the API will need access to the trace number. Without question, they will need to be able to read it. For Returns they will need to be able to set the trace number as it has to be the original number. Currently a Return, Dishonored Return, Contested Dishonored Return all use the same entry detail struct.

@adamdecaf
Copy link
Member Author

Gah, I forgot to imply a setter would exist. func (..) SetTraceNumber(str string) or something.

@adamdecaf
Copy link
Member Author

Doing so breaks an implicit 1:1 mapping we have from "ACH field" to "struct field".

Is this something we're ok with changing?

adamdecaf added a commit to adamdecaf/ach that referenced this issue Nov 19, 2018
This should point users towards getting the proper value rather than
using the int (which has known bugs).

Issue: moov-io#366
adamdecaf added a commit to adamdecaf/ach that referenced this issue Nov 27, 2018
adamdecaf added a commit to adamdecaf/ach that referenced this issue Nov 27, 2018
This should point users towards getting the proper value rather than
using the int (which has known bugs).

Issue: moov-io#366
@bkmoovio
Copy link
Contributor

#378

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants