22

After upgrading to ruby 1.9.3 one of my apps is working fine but the second one I am trying to convert fails at the "assets:precompile" stage when I try to deploy with capistrano. Here is the stacktrace:

 rake aborted!
 rake aborted!
 invalid byte sequence in US-ASCII
 /Users/george/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.4/lib/rake/trace_output.rb:16:in `block in trace_on'
 /Users/george/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.4/lib/rake/trace_output.rb:14:in `map'
 /Users/george/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.4/lib/rake/trace_output.rb:14:in `trace_on'
 /Users/george/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.4/lib/rake/application.rb:328:in `trace'
 /Users/george/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.4/lib/rake/application.rb:183:in `display_error_message'
 /Users/george/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.4/lib/rake/application.rb:169:in `rescue in standard_exception_handling'
 /Users/george/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.4/lib/rake/application.rb:159:in `standard_exception_handling'
 /Users/george/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.4/lib/rake/application.rb:88:in `load_rakefile'
 /Users/george/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.4/lib/rake/application.rb:72:in `block in run'
 /Users/george/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
 /Users/george/.rvm/gems/ruby-1.9.3-p392@global/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
 /Users/george/.rvm/gems/ruby-1.9.3-p392@rails3211/bin/ruby_noexec_wrapper:14:in `eval'
 /Users/george/.rvm/gems/ruby-1.9.3-p392@rails3211/bin/ruby_noexec_wrapper:14:in `<main>' 

I have read numerous posts and tried several suggestions but to no avail. I tried adding the following to the top of my gemfile:

if RUBY_VERSION =~ /1.9/
 Encoding.default_external = Encoding::UTF_8
 Encoding.default_internal = Encoding::UTF_8
end

But it made no difference.

I checked LANG and LC_ALL environment variables as follows

$ echo $LC_ALL
en_NZ.UTF-8
$ echo $LANG
en_NZ.UTF-8

I'm afraid I dont really understand the message at all and I dont know how to identify the file that has the problem.

I cant get any rake task to run - it gives the same error.

Note that I can run the application perfectly fine in development mode.

asked Apr 11, 2013 at 11:20
1
  • After searching randomly through files in the project. I decided that because the error message did not specify a filename for the problem then it was probably something to do with rake itself. Removing a rake task that contained hard coded data for database priming fixed the problem. Commented Apr 11, 2013 at 22:06

7 Answers 7

30

Add

#encoding: utf-8 

to the first line of your Rakefile (or whatever file has the strange characters in)

George Armhold
31.1k52 gold badges158 silver badges233 bronze badges
answered Apr 11, 2013 at 11:55
5
  • 1
    But how do I find which file that is? Commented Apr 11, 2013 at 12:09
  • 2
    No the problem file was not the Rakefile. That would have been easy!. It was one of my rake tasks that had the problem. Commented Apr 23, 2013 at 2:24
  • 2
    you can use the file command to identify the encoding: Rakefile: UTF-8 Unicode English text vs Rakefile: ASCII text Commented Nov 30, 2013 at 21:24
  • @timofei7 yes, but since ASCII text is actually a subset of UTF-8, setting UTF-8 should always work - unless, of course, the file has an odd encoding. Commented Sep 15, 2014 at 20:14
  • I nice command to show all files with their current encoding would be find . -exec file {} \; Commented Oct 6, 2015 at 18:02
5

Track down the rake file(s) at fault by deleting one at a time.

ie the files under lib/tasks/delete_me.rake

Then re-rake or restart which ever was giving you the issue. Once the issue is gone do a git diff to see which file was the culprit and with your favorite editor change the encoding of the file.

ie.,

vim lib/tasks/delete_me.rake :set fileencoding=utf-8 :wq

Then re-rake and you should be back in service.

answered Jul 30, 2013 at 20:41
2

First run

$ sudo gem install magic_encoding

Then go into the folder and run

$ magic_encoding

Ready!

SztupY
10.6k9 gold badges68 silver badges91 bronze badges
answered Mar 28, 2014 at 16:55
0
1

Make sure you're not typing in your file in romaji (Japanese). Or the English character setting for some other non US-ASCII language.

I tried running a rake db:seed and was getting a similar error. Turns out I had been typing in my seed file in the Japanese roman characters. I forgot to change my keyboard input back to US before working on my project.

ian
12.3k9 gold badges55 silver badges112 bronze badges
answered Jul 6, 2013 at 1:58
2
  • 1
    @BrenoSalgado he most likely add the correct encoding in the top of his file, or removed the characters from his seed file. Commented Sep 20, 2013 at 17:57
  • @BrenoSalgado Yea I simply deleted the characters that I had typed in Romaji, switch back to US English and retyped it. Commented Dec 5, 2013 at 1:16
1

I had the similar problem and the "error" was by my first name: It contains a non US-ASCII char (ö) This was printed in the setup.rb and caused the problems. I changed it to "oe" and it worked fine.

I will send an E-Mail to bitnami to let it changed somehow

answered Dec 6, 2013 at 10:40
0

I was getting the similar error while trying to run any rake task (I use Rails 3.2 with Ruby 1.9.3). I tried all the solutions above without any success. Later I found out that I was a specific gem that was causing the error (in my case it was the Faker gem, that was updated some days ago). I deleted the gem (it was not in use) and everything began to work! So, my advice is, if you run into this kind of issue and none of the solutions listed here work, check the version of each gem and see if any of them was been updated. Try to delete them or to set a compatible version.

answered Feb 23, 2016 at 13:53
0

This error popped out on a new project I was setting its dev env for work.

It was a rake task throwing the error, but on checking its file encoding, it was UTF-8.

So, this task in question was pulling data from another file (which also had UTF-8 encoding). The error persisted.

so, instead of reading the file as is (i.e. File.read("myfile.rb"))

I changed it to:

File.read("myfile.rb", :encoding => 'utf-8'), as per instructions of this solution, and all good again.

answered Nov 7, 2018 at 15:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.