isawnyu / geocollider-sinatra

Sinatra web app and frontend for Geocollider
2 stars 1 forks source link

ArgumentError: invalid byte sequence in UTF-8 #19

Open ryanfb opened 7 years ago

ryanfb commented 7 years ago

It looks like there may still be files that can raise this in geocollider-sinatra (in process). I figured this way of reading the file into a string in Geocollider::CSVParser would be robust enough, but apparently not. Not sure if this is only a geocollider-sinatra error or if it also needs a fix upstream in geocollider, so I've set a method in geocollider-sinatra here that should allow us to capture problematic files when an exception occurs: https://github.com/ryanfb/geocollider-sinatra/blob/master/geocollider-sinatra.rb#L170-L185

Example backtrace:

vendor/ruby-2.3.4/lib/ruby/2.3.0/csv.rb:1811 in sub!
vendor/ruby-2.3.4/lib/ruby/2.3.0/csv.rb:1811 in block in shift
vendor/ruby-2.3.4/lib/ruby/2.3.0/csv.rb:1805 in loop
vendor/ruby-2.3.4/lib/ruby/2.3.0/csv.rb:1805 in shift
vendor/ruby-2.3.4/lib/ruby/2.3.0/csv.rb:1747 in each
vendor/ruby-2.3.4/lib/ruby/2.3.0/csv.rb:1312 in parse
[GEM_ROOT]/bundler/gems/geocollider-ea1aa07b8c9e/lib/parsers/csv_parser.rb:60 in block in parse
[GEM_ROOT]/bundler/gems/geocollider-ea1aa07b8c9e/lib/parsers/csv_parser.rb:56 in each
[GEM_ROOT]/bundler/gems/geocollider-ea1aa07b8c9e/lib/parsers/csv_parser.rb:56 in parse
geocollider-sinatra.rb:142 in block (3 levels) in <class:GeocolliderSinatra>
vendor/ruby-2.3.4/lib/ruby/2.3.0/csv.rb:1282 in open
geocollider-sinatra.rb:137 in block (2 levels) in <class:GeocolliderSinatra>
vendor/ruby-2.3.4/lib/ruby/2.3.0/tempfile.rb:295 in open
geocollider-sinatra.rb:136 in block in <class:GeocolliderSinatra>
/gems/sinatra-1.4.8/lib/sinatra/base.rb:1611 in call
/gems/sinatra-1.4.8/lib/sinatra/base.rb:1611 in block in compile!
/gems/sinatra-1.4.8/lib/sinatra/base.rb:975 in block (3 levels) in route!
/gems/sinatra-1.4.8/lib/sinatra/base.rb:994 in route_eval
/gems/sinatra-1.4.8/lib/sinatra/base.rb:975 in block (2 levels) in route!
/gems/sinatra-1.4.8/lib/sinatra/base.rb:1015 in block in process_route
/gems/sinatra-1.4.8/lib/sinatra/base.rb:1013 in catch
/gems/sinatra-1.4.8/lib/sinatra/base.rb:1013 in process_route
/gems/sinatra-1.4.8/lib/sinatra/base.rb:973 in block in route!
/gems/sinatra-1.4.8/lib/sinatra/base.rb:972 in each
/gems/sinatra-1.4.8/lib/sinatra/base.rb:972 in route!
/gems/sinatra-1.4.8/lib/sinatra/base.rb:1085 in block in dispatch!
/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067 in block in invoke
/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067 in catch
/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067 in invoke
/gems/sinatra-1.4.8/lib/sinatra/base.rb:1082 in dispatch!
/gems/sinatra-1.4.8/lib/sinatra/base.rb:907 in block in call!
/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067 in block in invoke
/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067 in catch
/gems/sinatra-1.4.8/lib/sinatra/base.rb:1067 in invoke
/gems/sinatra-1.4.8/lib/sinatra/base.rb:907 in call!
/gems/sinatra-1.4.8/lib/sinatra/base.rb:895 in call
/gems/airbrake-6.0.0/lib/airbrake/rack/middleware.rb:52 in call
/gems/rack-protection-1.5.3/lib/rack/protection/xss_header.rb:18 in call
/gems/rack-protection-1.5.3/lib/rack/protection/path_traversal.rb:16 in call
/gems/rack-protection-1.5.3/lib/rack/protection/json_csrf.rb:18 in call
/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49 in call
/gems/rack-protection-1.5.3/lib/rack/protection/base.rb:49 in call
/gems/rack-protection-1.5.3/lib/rack/protection/frame_options.rb:31 in call
/gems/rack-1.6.5/lib/rack/nulllogger.rb:9 in call
/gems/rack-1.6.5/lib/rack/head.rb:13 in call
/gems/sinatra-1.4.8/lib/sinatra/base.rb:182 in call
/gems/sinatra-1.4.8/lib/sinatra/base.rb:2013 in call
/gems/rack-attack-5.0.1/lib/rack/attack.rb:147 in call
/gems/rack-1.6.5/lib/rack/handler/webrick.rb:88 in service
vendor/ruby-2.3.4/lib/ruby/2.3.0/webrick/httpserver.rb:140 in service
vendor/ruby-2.3.4/lib/ruby/2.3.0/webrick/httpserver.rb:96 in run
vendor/ruby-2.3.4/lib/ruby/2.3.0/webrick/server.rb:296 in block in start_thread