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

TypeError - nil can't be coerced into Integer #8

Open
dbourguignon opened this issue Jul 4, 2019 · 2 comments
Open

TypeError - nil can't be coerced into Integer #8

dbourguignon opened this issue Jul 4, 2019 · 2 comments

Comments

@dbourguignon
Copy link
Contributor

Hi,

With last version, trying to validate:

UkAccountValidator::Validator.new("6833861", "779136").valid?

Give this error:

Exception: TypeError: nil can't be coerced into Integer
--
0: /Users/davidbourguignon/.rvm/gems/ruby-2.5.3@drivy-rails/gems/uk_account_validator-0.0.8/lib/uk_account_validator/validators/standard_modulus.rb:18:in `*'
1: /Users/davidbourguignon/.rvm/gems/ruby-2.5.3@drivy-rails/gems/uk_account_validator-0.0.8/lib/uk_account_validator/validators/standard_modulus.rb:18:in `block (2 levels) in valid?'
2: /Users/davidbourguignon/.rvm/gems/ruby-2.5.3@drivy-rails/gems/uk_account_validator-0.0.8/lib/uk_account_validator/validators/standard_modulus.rb:15:in `each_pair'
3: /Users/davidbourguignon/.rvm/gems/ruby-2.5.3@drivy-rails/gems/uk_account_validator-0.0.8/lib/uk_account_validator/validators/standard_modulus.rb:15:in `each'
4: /Users/davidbourguignon/.rvm/gems/ruby-2.5.3@drivy-rails/gems/uk_account_validator-0.0.8/lib/uk_account_validator/validators/standard_modulus.rb:15:in `reduce'
5: /Users/davidbourguignon/.rvm/gems/ruby-2.5.3@drivy-rails/gems/uk_account_validator-0.0.8/lib/uk_account_validator/validators/standard_modulus.rb:15:in `block in valid?'
6: /Users/davidbourguignon/.rvm/gems/ruby-2.5.3@drivy-rails/gems/uk_account_validator-0.0.8/lib/uk_account_validator/validators/base_validator.rb:20:in `applying_exceptions'
7: /Users/davidbourguignon/.rvm/gems/ruby-2.5.3@drivy-rails/gems/uk_account_validator-0.0.8/lib/uk_account_validator/validators/standard_modulus.rb:14:in `valid?'
8: /Users/davidbourguignon/.rvm/gems/ruby-2.5.3@drivy-rails/gems/uk_account_validator-0.0.8/lib/uk_account_validator/validator.rb:46:in `block in valid?'
9: /Users/davidbourguignon/.rvm/gems/ruby-2.5.3@drivy-rails/gems/uk_account_validator-0.0.8/lib/uk_account_validator/validator.rb:39:in `each'

I looked a bit into it, but I don't know enough how this is suppose to work.
I checked on https://www.sortcodes.co.uk/ and apparently this is an invalid code.

Any clue?

@ball-hayden
Copy link
Owner

ball-hayden commented Jul 6, 2019

Hi @dbourguignon - sorry for the slow reply.

I'm afraid I can't really tell you much either - I wrote this a long time ago, and haven't actively used it since.

My guess is the problem here is the account number being 7 digits long - I would usually expect it to be 8, although I do recall there being some exceptions. If the sort code was invalid, the code might not take the correct exception (an overloaded word here... 🙄), so we've ended up trying to multiply by the 8th account number (which is nil).

If you fancy putting together a PR that tests for this case, I believe the correct behaviour would be to prefix the account number with a 0 (but it may be that this is already correctly handled when the sort code is correct - I'm afraid I forget).

I don't think I'd be comfortable merging anything without also testing a valid 7 digit account number though - I believe these are typically Lloyds or TSB.

@dbourguignon
Copy link
Contributor Author

@ball-hayden thanks for answering … I'll see if I can get more time for digging into it then

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

No branches or pull requests

2 participants