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.
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'
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?
Thanks in advance for any help!
EDIT: the problem isn't directrly related to psych gem. It's general problem with unusual ruby setup. See the accepted answer below for details.
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.
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}'
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/
Or perhaps create a shared group, such as src
, then:
chgrp src ~/.rbenv && chmod g+r -R ~/.rbenv
来源:https://stackoverflow.com/questions/13277729/ruby-loaderror-enc-trans-single-byte