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.