breaking into the unknown…

ArgumentError: invalid byte sequence in US-ASCII

Leave a comment

I have automated my rails deployment with Capistrano. It was working fine. I have added a new gem useragent to my Gemfile as below

gem 'useragent', '0.2.3', :git => ""

I committed the code and when try to deploy the code again got below error

2013-09-17 16:50:35 executing `bundle:install'
    [root@] executing command
 ** [out :: root@] ArgumentError: invalid byte sequence in US-ASCII
 ** [out :: root@] An error occurred while installing useragent (0.2.3),
 ** [out :: root@]  and Bundler cannot continue.
 ** [out :: root@] Make sure that `gem install useragent -v '0.2.3'`
    succeeds before bundling.

The issue is discussed in length here at bundler issue tracking .

The reason is that by default ruby set to evaluate any file as US-ASCII encoding. But useragent gem is having some non ASCII characters in it, so throwing the error. It can be solved by setting the default language to utf-8 which support much wider range of encoding. The solution is to add below line to Gemfile at the top.

if RUBY_VERSION =~ /1.9/ # assuming you're running Ruby ~1.9
  Encoding.default_external = Encoding::UTF_8
  Encoding.default_internal = Encoding::UTF_8

Author: arunyadav4u

over 7 years experience in web development with Ruby on Rails.Involved in all stage of development lifecycle : requirement gathering, planing, coding, deployment & Knowledge transfer. I can adept to any situation, mixup very easily with people & can be a great friend.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s