简体   繁体   English

rake任务因US-ASCII中的无效字节序列而失败

[英]rake tasks fail with invalid byte sequence in US-ASCII

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. 在升级到ruby 1.9.3之后,我的一个应用程序工作正常,但是当我尝试使用capistrano进行部署时,我尝试转换的第二个应用程序在“assets:precompile”阶段失败。 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: 我尝试将以下内容添加到我的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 我检查了LANG和LC_ALL环境变量,如下所示

$ 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. 我不能运行任何rake任务 - 它给出了同样的错误。

Note that I can run the application perfectly fine in development mode. 请注意,我可以在开发模式下完美地运行应用程序。

Add

#encoding: utf-8 

to the first line of your Rakefile (or whatever file has the strange characters in) 到你的Rakefile的第一行(或任何有奇怪字符的文件)

Track down the rake file(s) at fault by deleting one at a time. 通过一次删除一个错误的rake文件来追踪它

ie the files under lib/tasks/delete_me.rake 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. 一旦问题消失,请执行git diff以查看哪个文件是罪魁祸首,并使用您喜欢的编辑器更改文件的编码。

ie., 即,

vim lib/tasks/delete_me.rake :set fileencoding=utf-8 :wq 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). 确保你没有在romaji(日语)中输入你的文件。 Or the English character setting for some other non US-ASCII language. 或其他非US-ASCII语言的英文字符设置。

I tried running a rake db:seed and was getting a similar error. 我尝试运行rake db:seed并得到类似的错误。 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. 在处理我的项目之前,我忘记将键盘输入更改回美国。

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. 我有类似的问题,“错误”是我的名字:它包含一个非US-ASCII字符(ö)这是在setup.rb中打印并导致问题。 I changed it to "oe" and it worked fine. 我把它改成了“oe”,它工作得很好。

I will send an E-Mail to bitnami to let it changed somehow 我会发送一封电子邮件给bitnami让它以某种方式改变

I was getting the similar error while trying to run any rake task (I use Rails 3.2 with Ruby 1.9.3). 我在尝试运行任何rake任务时遇到了类似的错误(我使用Rails 3.2和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). 后来我发现我是一个导致错误的特定宝石(在我的情况下,它是Faker宝石,几天前更新)。 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. 因此,我的建议是,如果您遇到此类问题并且此处列出的解决方案均无效,请检查每个gem的版本并查看其中是否有任何更新。 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. 这是一个抛出错误的rake任务,但在检查其文件编码时,它是UTF-8。

So, this task in question was pulling data from another file (which also had UTF-8 encoding). 因此,这个任务是从另一个文件(也有UTF-8编码)中提取数据。 The error persisted. 错误仍然存​​在。

so, instead of reading the file as is (ie File.read("myfile.rb") ) 所以,而不是按原样读取文件(即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. File.read("myfile.rb", :encoding => 'utf-8') ,按照此解决方案的说明,再次全部好。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rails:运行 rake db:seed 时 US-ASCII 中的字节序列无效(参数错误) - Rails: Invalid byte sequence in US-ASCII (Argument Error) when I run rake db:seed US-ASCII whith数组中的无效字节序列 - invalid byte sequence in US-ASCII whith array MembersController中的ArgumentError#登录US-ASCII中的无效字节序列 - ArgumentError in MembersController#login invalid byte sequence in US-ASCII US-ASCII(ArgumentError)中的字节序列无效,没有任何帮助 - invalid byte sequence in US-ASCII (ArgumentError), nothing helps ArgumentError(US-ASCII中无效的字节序列):在ruby升级1.9.3中 - ArgumentError (invalid byte sequence in US-ASCII): in ruby upgrade 1.9.3 bundle install error“US-ASCII(ArgumentError)中的无效字节序列” - bundle install error “invalid byte sequence in US-ASCII (ArgumentError)” Heroku-US-ASCII中的无效字节序列(ArgumentError) - Heroku - invalid byte sequence in US-ASCII (ArgumentError) 将Ruby升级到1.9.2后,Rails查看错误“US-ASCII中的无效字节序列”错误 - Rails view error “invalid byte sequence in US-ASCII” error after upgrading Ruby to 1.9.2 US-ASCII中的无效字节序列(Ruby 1.9 + rails 2.3.8 + mongodb + mongo_mapper) - invalid byte sequence in US-ASCII (Ruby 1.9 + rails 2.3.8 + mongodb + mongo_mapper) RVM,Ruby 1.9.2,Rails 2.3.8,Passenger和“US-ASCII中的无效字节序列” - RVM, Ruby 1.9.2, Rails 2.3.8, Passenger and “invalid byte sequence in US-ASCII”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM