ideal-postcodes / ideal-postcodes-ruby

UK postcode lookup API using Royal Mail's Postcode Address File.
https://ideal-postcodes.co.uk
MIT License
12 stars 3 forks source link

ID1 CLIP and ID1 CHOP throw undefined method 'nil' for Fixnum exception #1

Closed tomsabin closed 10 years ago

tomsabin commented 10 years ago

ideal_postcodes (0.1.0) rails (4.1.5) ruby-2.1.2

As documented under the "testing" heading in https://ideal-postcodes.co.uk/documentation, the following two postcodes break the gem:

Daily usage (ID1 CHOP)

 $ rails c
Loading development environment (Rails 4.1.5)
2.1.2 :001 > daily_usage = IdealPostcodes::Postcode.lookup('ID1CHOP')
IdealPostcodes::LimitReachedError: /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/ideal_postcodes-0.1.0/lib/idealpostcodes/errors.rb:17:in `to_s': undefined method `nil' for 4021:Fixnum (NoMethodError)
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:501:in `write'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:501:in `print'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:501:in `block (2 levels) in eval_input'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:624:in `signal_status'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:489:in `block in eval_input'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/ruby-lex.rb:247:in `block (2 levels) in each_top_level_statement'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/ruby-lex.rb:233:in `loop'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/ruby-lex.rb:233:in `block in each_top_level_statement'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/ruby-lex.rb:232:in `catch'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/ruby-lex.rb:232:in `each_top_level_statement'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:488:in `eval_input'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:397:in `block in start'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:396:in `catch'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:396:in `start'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/railties-4.1.5/lib/rails/commands/console.rb:90:in `start'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/railties-4.1.5/lib/rails/commands/console.rb:9:in `start'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:69:in `console'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/railties-4.1.5/lib/rails/commands.rb:17:in `<top (required)>'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `require'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `block in require'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:232:in `load_dependency'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `require'
  from /Users/tomsabin/Repositories/repo/bin/rails:8:in `<top (required)>'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `load'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `block in load'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:232:in `load_dependency'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `load'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
  from -e:1:in `<main>'

No lookups remaining (ID1 CLIP)

 $ rails c
Loading development environment (Rails 4.1.5)
2.1.2 :001 > no_lookups_remaining = IdealPostcodes::Postcode.lookup('ID1 CLIP')
IdealPostcodes::TokenExhaustedError: /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/ideal_postcodes-0.1.0/lib/idealpostcodes/errors.rb:17:in `to_s': undefined method `nil' for 4020:Fixnum (NoMethodError)
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:501:in `write'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:501:in `print'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:501:in `block (2 levels) in eval_input'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:624:in `signal_status'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:489:in `block in eval_input'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/ruby-lex.rb:247:in `block (2 levels) in each_top_level_statement'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/ruby-lex.rb:233:in `loop'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/ruby-lex.rb:233:in `block in each_top_level_statement'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/ruby-lex.rb:232:in `catch'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb/ruby-lex.rb:232:in `each_top_level_statement'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:488:in `eval_input'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:397:in `block in start'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:396:in `catch'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/irb.rb:396:in `start'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/railties-4.1.5/lib/rails/commands/console.rb:90:in `start'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/railties-4.1.5/lib/rails/commands/console.rb:9:in `start'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:69:in `console'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/railties-4.1.5/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/railties-4.1.5/lib/rails/commands.rb:17:in `<top (required)>'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `require'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `block in require'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:232:in `load_dependency'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:247:in `require'
  from /Users/tomsabin/Repositories/repo/bin/rails:8:in `<top (required)>'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `load'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `block in load'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:232:in `load_dependency'
  from /Users/tomsabin/.rvm/gems/ruby-2.1.2@gemset/gems/activesupport-4.1.5/lib/active_support/dependencies.rb:241:in `load'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
  from /Users/tomsabin/.rvm/rubies/ruby-2.1.2/lib/ruby/site_ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
  from -e:1:in `<main>'
cblanc commented 10 years ago

Thanks for making us aware. That's definitely not the exception it should be raising. It should be raising IdealPostcodes::LimitReachedError and IdealPostcodes::TokenExhaustedError respectively.

We just pushed an update (0.1.1) which should fix that problem. Also added much needed documentation on error handling.

This wrapper is definitely getting a bit long in the tooth now, so we'll spend some time this week pushing more updates. No breaking changes - mainly adding the newer API methods, updating dependencies and enabling CI.

cblanc commented 10 years ago

@tomsabin - hopefully everything is working fine. Let me know if not. Otherwise I will close issue #1 end of today. Thanks

tomsabin commented 10 years ago

Perfect, thanks for the swift response @cblanc. I have updated to 0.1.1 and all is working as intended.