zverok / wheretz

Fast and precise time zone by geo coordinates lookup
MIT License
99 stars 12 forks source link

NoMethodError: undefined method `y' for false:FalseClass #5

Closed jotolo closed 4 years ago

jotolo commented 5 years ago
@timezone_id ||= WhereTZ.lookup(x.latitude, x.longitude) ||
                        session_params[:timezone_id]

     NoMethodError:
       undefined method `y' for false:FalseClass

This is happening randomly in some code I use everyday. Any ideas?

zverok commented 5 years ago

Can you please provide the full error backtrace?

jotolo commented 5 years ago

There is no error backtrace. The rest is from my code in my application because I'm getting the error from my specs :( I know this is not helpful, sorry.

jotolo commented 5 years ago

It's crazy, now I got this:

NoMethodError:
       undefined method `map' for false:FalseClass
       Did you mean?  tap
zverok commented 5 years ago

Somehow it receives false somewhere deep in the internals, where other data expected. I don't see anything that uses y method in the library's code, so it is either some underlying libraries, or your client code. Backtrace of the error (what exact chain of calls lead to it) could really help.

jotolo commented 5 years ago

I'm going to check what longitude and latitude is passing as argument. I will let you know. Thank you!

sfate commented 5 years ago

I suppose it goes from GeoRuby lib as there is underlying methods (with y variable definition) which this lib is using.

jotolo commented 5 years ago

@zverok Could you please, check @sfate comment?

zverok commented 5 years ago

@jotolo I really need more information for debugging, some reproducible test case or at least detailed backtrace to the place where the error really happens. It is really hard to guess otherwise

jotolo commented 5 years ago

@zverok I've got some information for you. It's useful. It's kinda the same issue.

from /var/www/backend/vendor/bundle/ruby/2.5.0/gems/wheretz-0.0.2/lib/wheretz.rb:49:in `lookup'
       11: from /var/www/backend/vendor/bundle/ruby/2.5.0/gems/wheretz-0.0.2/lib/wheretz.rb:86:in `lookup_geo'
       10: from /var/www/backend/vendor/bundle/ruby/2.5.0/gems/wheretz-0.0.2/lib/wheretz.rb:86:in `select'
        9: from /var/www/backend/vendor/bundle/ruby/2.5.0/gems/wheretz-0.0.2/lib/wheretz.rb:87:in `block in lookup_geo'
        8: from /var/www/backend/vendor/bundle/ruby/2.5.0/gems/wheretz-0.0.2/lib/wheretz.rb:87:in `any?'
        7: from /var/www/backend/vendor/bundle/ruby/2.5.0/gems/wheretz-0.0.2/lib/wheretz.rb:87:in `block (2 levels) in lookup_geo'
        6: from /var/www/backend/vendor/bundle/ruby/2.5.0/gems/georuby-2.5.2/lib/geo_ruby/simple_features/polygon.rb:97:in `contains_point?'
        5: from /var/www/backend/vendor/bundle/ruby/2.5.0/gems/georuby-2.5.2/lib/geo_ruby/simple_features/polygon.rb:97:in `select'
        4: from /var/www/backend/vendor/bundle/ruby/2.5.0/gems/georuby-2.5.2/lib/geo_ruby/simple_features/polygon.rb:97:in `block in contains_point?'
        3: from /var/www/backend/vendor/bundle/ruby/2.5.0/gems/georuby-2.5.2/lib/geo_ruby/simple_features/linear_ring.rb:26:in `contains_point?'
        2: from /var/www/backend/vendor/bundle/ruby/2.5.0/gems/georuby-2.5.2/lib/geo_ruby/simple_features/linear_ring.rb:26:in `select'
        1: from /var/www/backend/vendor/bundle/ruby/2.5.0/gems/georuby-2.5.2/lib/geo_ruby/simple_features/linear_ring.rb:27:in `block in contains_point?'
NoMethodError (undefined method `>' for nil:NilClass)
jotolo commented 5 years ago

PR created to fix this issue in georuby library.

zverok commented 5 years ago

@jotolo I am not sure it is a bug in GeoRuby per se... Maybe a bug in data. If I understand your PR correctly, that happens that in some of geometry features loaded from WhereTZ source files, there is some point that has x or y as nil, right?.. I believe it is either of two:

  1. Bug in the data (could be probably spotted by GeoRuby on loading, but not necessarily)
  2. Bug in GeoRuby data loading (it loads perfectly sane data in a way that it now has some nils)

Either way:

jotolo commented 5 years ago

@zverok Sorry about the late reply. In this log file you can find an example of the multipolygon and a point causing the issue. Also, the small backtrace was added to the file. Please, let me know if you find the issue here. It's a strange issue regarding some nil values. Thanks in advance.

zverok commented 4 years ago

@jotolo Sorry about me replying lately myself, but I still don't quite get it :( Your logs say the problematic point is:

#<GeoRuby::SimpleFeatures::Point:0x0000562778bc1358 @srid=4326, @with_z=false, @with_m=false, @y=14.282239542427845, @x=-82.84276949121094, @z=0.0, @m=0.0>

(which means lat -82.84276949121094, lng 14.282239542427845) But

WhereTZ.lookup(-82.84276949121094, 14.282239542427845)
# => "Antarctica/Troll" 

It is really hard to hunt for the bug without reproducible case :(

jotolo commented 4 years ago

@zverok Thanks for checking this out. It turns out this issue was caused by random and invalid data in this case. If someone else has issues like this one in the future make sure you're using correct longitude and latitude values.