Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rake tasks fail with invalid byte sequence in US-ASCII

Tags:

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.

like image 211
giorgio Avatar asked Apr 11 '13 11:04

giorgio


2 Answers

Add

#encoding: utf-8  

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

like image 53
fotanus Avatar answered Sep 21 '22 01:09

fotanus


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.

like image 20
f1v Avatar answered Sep 23 '22 01:09

f1v