Rails - invalid byte sequence in US-ASCII
character-encoding, compatibility, ruby-on-rails-3
Solution
So, I finally found the solution by checking out every commit in the history (`git log`), testing, and finally making a `git diff <commit_hash> <previous_commit_hash>` to see what changed.
I had non-ASCII char in a helper (loaded on every call apparently):
def group_currency(group)
currency = group.currency
case currency
when 'EUR'
haml_tag "€"
when 'USD'
haml_tag "$"
when 'GBP'
haml_tag "£"
end
end
So adding this at the beggining of the file solves it:
#encoding: utf-8
module GroupsHelper
...
But what I find more questionning is why can't Rails locate and report in the log the file that rises the problem... I created an issue on Rails for this: https://github.com/rails/rails/issues/12041
Problem
I'm losing all my hair on this: My rails server starts ok, but whichever the request to it is made (except assets and public content), I get this error : ``` ArgumentError in HomeController#index invalid byte sequence in US-ASCII ``` with this framework trace (no application trace) ``` better_errors (0.9.0) lib/better_errors/stack_frame.rb:19:in `from_exception' better_errors (0.9.0) lib/better_errors/error_page.rb:52:in `backtrace_frames' better_errors (0.9.0) lib/better_errors/middleware.rb:114:in `log_exception' better_errors (0.9.0) lib/better_errors/middleware.rb:87:in `rescue in protected_app_call' better_errors (0.9.0) lib/better_errors/middleware.rb:84:in `protected_app_call' better_errors (0.9.0) lib/better_errors/middleware.rb:79:in `better_errors_call' better_errors (0.9.0) lib/better_errors/middleware.rb:56:in `call' actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call' actionpack (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call' railties (3.2.13) lib/rails/rack/logger.rb:32:in `call_app' railties (3.2.13) lib/rails/rack/logger.rb:16:in `block in call' activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in `tagged' railties (3.2.13) lib/rails/rack/logger.rb:16:in `call' actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:in `call' rack (1.4.5) lib/rack/methodoverride.rb:21:in `call' rack (1.4.5) lib/rack/runtime.rb:17:in `call' activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in `call' rack (1.4.5) lib/rack/lock.rb:15:in `call' actionpack (3.2.13) lib/action_dispatch/middleware/static.rb:63:in `call' railties (3.2.13) lib/rails/engine.rb:479:in `call' railties (3.2.13) lib/rails/application.rb:223:in `call' rack (1.4.5) lib/rack/content_length.rb:14:in `call' railties (3.2.13) lib/rails/rack/log_tailer.rb:17:in `call' rack (1.4.5) lib/rack/handler/webrick.rb:59:in `service' /home/augustin/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service' /home/augustin/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run' /home/augustin/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread' ``` My team works on windows and it works fine on their platform, but the bug occurs on my computer in ubuntu. Everything worked fine until now, if I rollback to my latest commit it works again, so the error is in the merge. Questions are: - How can I debug this issue since it's not really verbose? - What does the error actually means? That Ascii is expected and that's not what we have OR that ascii is found and that's not what's expected? - Is the error more likely to be in a gem, in the application controller? - Is there a way to filter all special characters to have an idea where it comes from? - What other info would be usefull to help me debug this? Readings: - When run bundle get invalid byte sequence in US-ASCII : both solutions offered didn't work for me - is there a way to highlight all the special accent characters in sublime text or any other text editor? : many results, but nothing especially weird Attached: `Gemfile` ``` source 'https://rubygems.org' gem 'rails', '3.2.13' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' # Database gem 'pg' # Database Init gem 'seed_dump' # gem "seedbank" # gem 'active_model_serializers' # HAML gem 'haml', '4.0.3' gem 'html2haml' # Front-end gem 'jquery-rails' gem 'bootstrap-sass', :git => 'git://github.com/thomas-mcdonald/bootstrap-sass.git', :branch => '3' # gem 'font-awesome-sass-rails' gem 'font-awesome-rails' gem 'bootstrap-datepicker-rails' gem 'jquery-tokeninput-rails' # tag and autocomplete for conversation # Shared mustache templates for rails 3. gem 'smt_rails' # Attachements gem 'paperclip', '3.4.2' # Share on Social Network gem 'social-share-button' # Jquery Upload File # gem "jquery.fileupload-rails" # Map gem 'mapbox-rails', :git => 'https://github.com/aug-riedinger/mapbox-rails.git' gem 'leaflet-markercluster-rails' # Authentication gem 'bcrypt-ruby', '3.0.1', :require => 'bcrypt' gem 'devise' gem 'omniauth' gem 'omniauth-facebook', "1.4.0" gem 'oauth2' gem 'fb_graph' # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3.2.1' gem 'coffee-script-source', '1.5.0' gem 'uglifier', '>= 1.0.3' end group :development, :test do gem 'better_errors' gem 'binding_of_caller' end platforms :ruby do group :development, :test do gem 'railroady' end group :production do gem 'aws-sdk' gem 'unicorn' gem 'newrelic_rpm' end end # Messaging - Notifications gem 'simple_form' gem 'mailboxer' gem 'pusher' gem 'amistad' # Pdf generation gem 'prawn' gem 'prawnto' # Payments gem 'activemerchant' # SEO gem 'dynamic_sitemaps' gem 'metamagic' # Static files gem 'markdown-rails' ``` Thanks for helping a desesperate guy ...