Ruby-LoadError enc / trans / single_byte [英] Ruby - LoadError enc/trans/single_byte

查看:65
本文介绍了Ruby-LoadError enc / trans / single_byte的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Ruby on Rails应用程序中使用ActiveRecord :: Store模块时遇到了一个奇怪的问题。据我了解,该模块在后台使用序列化方法,因此它仅使用内置的ruby内置心理宝石将数据序列化为yaml格式。

I encountered a weird problem while using ActiveRecord::Store module in my Ruby on Rails app. As I understand, this module use 'serialize' method under the hood so it just serialize your data to yaml format with ruby built-in psych gem.

最有效有时,但有时出现500错误,并显示以下消息:

It works OK most of the time, but sometimes I get 500 error with the following message:

LoadError (cannot load such file -- enc/trans/single_byte):
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/psych/visitors/emitter.rb:27:in `write'
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/psych/visitors/emitter.rb:27:in `end_document'
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/psych/visitors/emitter.rb:27:in `visit_Psych_Nodes_Document'
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/psych/visitors/visitor.rb:15:in `visit'
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/psych/visitors/visitor.rb:5:in `accept'
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/psych/visitors/emitter.rb:20:in `block in visit_Psych_Nodes_Stream'
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/psych/visitors/emitter.rb:20:in `each'
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/psych/visitors/emitter.rb:20:in `visit_Psych_Nodes_Stream'
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/psych/visitors/visitor.rb:15:in `visit'
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/psych/visitors/visitor.rb:5:in `accept'
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/psych/nodes/node.rb:46:in `yaml'
~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/psych.rb:243:in `dump'

我使用rbenv和ruby 1.9.3-p286。我的系统是Ubuntu 11.10。所需文件存在〜/ .rbenv / versions / 1.9.3-p286 / lib / ruby​​ / 1.9.1 / i686-linux / enc / trans / single_byte.so 。我在ruby 1.9.3-p194中遇到的相同错误。这个问题最奇怪的部分是不时发生此错误。

As you can see, I use rbenv and ruby 1.9.3-p286. My system is Ubuntu 11.10. Required file exists ~/.rbenv/versions/1.9.3-p286/lib/ruby/1.9.1/i686-linux/enc/trans/single_byte.so. The same error I encountered with ruby 1.9.3-p194. And the most weird part of this problem that this error occurs from time to time.

所以也许有人也遇到了这个问题,并且已经找到了解决方案?还是看起来更像是心理错误,我应该将其提交给其维护人员?

So maybe someone encountered this problem too and has already found a solution? Or does it seem more like a bug in psych and I should file it to its maintainer?

在此先感谢您的帮助!

编辑:该问题与psych gem没有直接关系。这是红宝石设置异常的普遍问题。有关详细信息,请参见下面可接受的答案。

the problem isn't directrly related to psych gem. It's general problem with unusual ruby setup. See the accepted answer below for details.

推荐答案

这是否发生在开发环境的舒适范围内?如果是这样,我会考虑在 pry-rescue Pry.rescue中运行…结束块并戳

Is this happening within the cozy confines of your development environment? If so, I'd consider running it under pry-rescue's Pry.rescue do … end block and poking around while there.

我怀疑数据有差异。此树中是否有意涉及任何非ASCII?您可以使用类似这样的东西来查找它:

I suspect a data difference. Is there any non-ASCII intentionally involved in this tree? You could hunt it down with something like this:

ruby -e 'Dir["**/*.yml"].each{|e| File.read(e)[/[^\x0-\x7f]/] and puts e}' 

如下所示,rbenv安装与其他用户共享,因此请确保在进行任何更改后重做权限:

As you indicated below, the rbenv installation is shared with other users, so be sure to redo the permissions upon any change:

 chmod a+r -R ~/.rbenv/

或者创建一个共享组,例如 src ,然后:

Or perhaps create a shared group, such as src, then:

 chgrp src ~/.rbenv && chmod g+r -R ~/.rbenv

这篇关于Ruby-LoadError enc / trans / single_byte的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆