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.
-
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.giorgio– giorgio2013年04月11日 22:06:20 +00:00Commented Apr 11, 2013 at 22:06
7 Answers 7
Add
#encoding: utf-8
to the first line of your Rakefile (or whatever file has the strange characters in)
-
1But how do I find which file that is?giorgio– giorgio2013年04月11日 12:09:37 +00:00Commented Apr 11, 2013 at 12:09
-
2No the problem file was not the Rakefile. That would have been easy!. It was one of my rake tasks that had the problem.giorgio– giorgio2013年04月23日 02:24:13 +00:00Commented Apr 23, 2013 at 2:24
-
2you can use the
file
command to identify the encoding:Rakefile: UTF-8 Unicode English text vs Rakefile: ASCII text
timofei7– timofei72013年11月30日 21:24:53 +00:00Commented 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.fotanus– fotanus2014年09月15日 20:14:13 +00:00Commented Sep 15, 2014 at 20:14
-
I nice command to show all files with their current encoding would be
find . -exec file {} \;
Cyclonecode– Cyclonecode2015年10月06日 18:02:11 +00:00Commented Oct 6, 2015 at 18:02
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.
First run
$ sudo gem install magic_encoding
Then go into the folder and run
$ magic_encoding
Ready!
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.
-
1@BrenoSalgado he most likely add the correct encoding in the top of his file, or removed the characters from his seed file.fotanus– fotanus2013年09月20日 17:57:27 +00:00Commented 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.user2031423– user20314232013年12月05日 01:16:51 +00:00Commented Dec 5, 2013 at 1:16
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
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.
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.
Explore related questions
See similar questions with these tags.