rake tasks fail with invalid byte sequence in US-ASCII

giorgio picture giorgio · Apr 11, 2013 · Viewed 14.5k times · Source

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.

Answer

fotanus picture fotanus · Apr 11, 2013

Add

#encoding: utf-8 

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