Ruby - LoadError enc/trans/single_byte
Asked Answered
J

1

6

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.

Jana answered 7/11, 2012 at 20:33 Comment(0)
F
1

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
Ferromagnetism answered 15/11, 2012 at 15:13 Comment(1)
rking, thanks for your advice! You pointed me to right direction. It's solved. The problem was trivial: I use non ASCII characters in my source code so I have to turn on unicode mode in ruby interpreter (through magic comments). But because of unusual setup (home directory where ruby was installed closed from access by other users) ruby couldn't use its internal stuff to transcode my code. Solution: open dir where ruby is installed to at least user who launch ruby interpreter. rking, could you complete your answer with this info so I can accept it as a final solution? I hope it helps someone.Jana

© 2022 - 2024 — McMap. All rights reserved.