Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

uninitialized constant Encoding::US_ASCII installing activerecord gem #163

Open
atownley opened this issue Nov 18, 2011 · 22 comments
Open
Labels

Comments

@atownley
Copy link
Contributor

Hi folks,

I've been googling and didn't see a reference to this particular issue, so I thought I'd ask it here. I'm trying to load the following test Shoes app:

Shoes.setup do
  gem 'activerecord'
end

require 'active_record'

class Foo < ActiveRecord::Base; end

Shoes.app do
  para "it works"
end

And all seems to start OK, but then I get the following stack trace:

Error in <unknown> line 0
    uninitialized constant Encoding::US_ASCII /Applications/Shoes.app/Contents/MacOS/ruby/lib/uri/common.rb:226:in `escape'
    /Applications/Shoes.app/Contents/MacOS/ruby/lib/rubygems/remote_fetcher.rb:92: in `download'
    /Applications/Shoes.app/Contents/MacOS/ruby/lib/rubygems/dependency_installer.rb:257:in `block in install'
    /Applications/Shoes.app/Contents/MacOS/ruby/lib/rubygems/dependency_installer.rb:247:in `each'
    /Applications/Shoes.app/Contents/MacOS/ruby/lib/rubygems/dependency_installer.rb:247:in `install'
    /Applications/Shoes.app/Contents/MacOS/ruby/lib/shoes/setup.rb:132:in `block in start'
    /Applications/Shoes.app/Contents/MacOS/ruby/lib/shoes/setup.rb:122:in `each'
    /Applications/Shoes.app/Contents/MacOS/ruby/lib/shoes/setup.rb:122:in `start'
    /Applications/Shoes.app/Contents/MacOS/ruby/lib/shoes/setup.rb:57:in `block (4 levels) in setup_app'

The gem installation also fails to install on Vista, but the console window is black so I can't see the stack trace. In both cases, this is Policeman from the binary downloads for each platform. The windows one has the video components installed.

BTW, it'd be really handy if you could copy/paste from the console window! :)

Thanks in advance for any help.

Cheers,

ast

@steveklabnik
Copy link
Member

Interesting. This is the first report of an encoding issue on the 1.9.1 based Shoes. Which the Policeman build is. Encoding stuff should only happen like that in 1.9.2... how strange.

This is from the one you downloaded from the site, or did you compile your own Shoes?

BTW, it'd be really handy if you could copy/paste from the console window! :)

Yeah, that'd be good, I agree.

@atownley
Copy link
Contributor Author

The OSX version is 1739. Both the OSX and the Windows versions were downloaded from the shoesrb.com/downloads links.

It looks like the offending line is here in common.rb:

214     def escape(str, unsafe = @regexp[:UNSAFE])
215       unless unsafe.kind_of?(Regexp)
216         # perhaps unsafe is String object
217         unsafe = Regexp.new("[#{Regexp.quote(unsafe)}]", false)
218       end
219       str.gsub(unsafe) do
220         us = $&
221         tmp = ''
222         us.each_byte do |uc|
223           tmp << sprintf('%%%02X', uc)
224         end
225         tmp
226 #      end.force_encoding(Encoding::US_ASCII)
227       end
228     end

So, I just commented out the #force_encoding call in my OSX version so I could get on with what I was trying to do. Obviously, this isn't exactly the ideal solution.

From googling, this seemed to be the most relevant result, but isn't Shoes related: brianmario/mysql2#178

My guess is that something strange is happening with namespaces somewhere, but I don't have any specific evidence for that. Once I commented out the #force_encoding, the gem installed and the above code works fine.

@steveklabnik
Copy link
Member

Ah, I misread your report. The Mac version is based on 1.9.2, so that makes a lot more sense.

What's happening is that we're not getting all of the encodings loaded somehow. @wasnotrice and I were looking into it, but we still haven't figured out what's up. This is the root reason that the 1.9.1 to 1.9.2 move was so hard for us, so it sucks to see it cropping up...

@atownley
Copy link
Contributor Author

It is?

valkyrie$ ./shoes -v
shoes policeman (0.r1739) [universal.x86_64-darwin11.1.0 Ruby1.9.1]

Apologies. I should've put this in originally.

@wasnotrice
Copy link
Member

@atownley yeah, it is 1.9.2 even though it says 1.9.1. There are lots of places in ruby 1.9.2 that refer to ruby 1.9.1 (lib/libruby.1.9.1.dylib for instance). We're picking up the wrong config var there in the versioning. I found the right one now, though. Thanks!

@steveklabnik
Copy link
Member

This is due to Ruby having a 'library compatability version' of 1.9.1, even with 1.9.2. sudo apt-get install ruby1.9.1 on debian installs 1.9.2.

It's silly. Oh well.

@wasnotrice
Copy link
Member

So this doesn't address the encoding issue, but the ruby version is fixed by b30ed20

Now:

su:MacOS eric$ ./shoes -v
shoes policeman (0.r1741) [universal-darwin11.2.0 Ruby1.9.2]

@atownley
Copy link
Contributor Author

Ok. Thanks for the clarifications and the fix for the version stuff. Makes more sense now.

@itsalljustaride
Copy link

I'm seeing this same issue.

Using Policeman rev 1739

@atownley
Copy link
Contributor Author

Actually, this gets worse once you try and save anything. The Encoding thing bites you in the backside all over the place.

The only way I was actually able to continue with what I was doing was to hack the .shoes/+gem/gems/activesupport-3.1.2/lib/active_support/core_ext/string/encoding.rb file to force it to define #encoding_aware? to return false. Doing this (and the above) will allow you to use AR as expected.

@itsalljustaride
Copy link

I recieved it when trying to use the serialport gem.

@Jirapong
Copy link

I am able to do the monkey patch after require 'activerecord' as following

11 class Encoding
12    US_ASCII = 'US-ASCII'
13 end
14
15 class String
16    def encoding_aware?
17       false
18    end
19
20    def force_encoding(enc)
21       self
22    end
23 end

and also i think this can be fix in shoes.rb by add US_ASCII to the line#22

21 class Encoding
22  %w[ASCII_8BIT US_ASCII UTF_16BE UTF_16LE UTF_32BE UTF_32LE].each do |ec|
23    eval "#{ec} = '#{ec.sub '_', '-'}'"
24  end unless RUBY_PLATFORM =~ /linux/
25 end 

@surfnext
Copy link

Thank you, Jirapong! Another piece in the puzzle of getting Mysql2 to work on Windows 7.

http://blog.ideaday.de/max/2012/03/ruby-shoes-and-the-mysql2-gem-on-windows-7/

I've listed the correct patch for all the values you need, taken from the client.rb of Mysql2.

Unfortunately we still run into issues: the call never returns and execution hangs at this point.

@steveklabnik
Copy link
Member

Small note about your blog post, @surfnext : Policeman ships with Ruby 1.9.1, not 1.9.2. You might be building shoes from HEAD, which can have 1.9.2 or 1.9.3.

@surfnext
Copy link

Thanks, fixed in the article. I use policeman.

@ZaiLynch
Copy link

Having the same issue when trying to install the xml-simple gem

@maximillion90
Copy link

I have just seen this when trying to install both watir and cucumber, any info on the fix without hacking ruby or the operating system?

@PragTob
Copy link
Member

PragTob commented Nov 12, 2013

No real idea, I'm sorry. Maybe building/compiling shoes yourself could resolve the issue (well it always worked for me) but no guarantees whatsoever :o

Tobi

@maximillion90
Copy link

Will Shoes four fix the issue? :) Also as a bit of a new comer, how would I go about compiling it myself?

@PragTob
Copy link
Member

PragTob commented Nov 12, 2013

You can read about building shoes in the wiki.

And shoes4 is a complete rewrite also with different technology underneath (JRuby + SWT) - so it won't have this issue. Therefore most likely some other issues which we are eagerly working on fixing :-)

Tobi

@maximillion90
Copy link

Ha ha, software tester by trade so believe me i feel your pain. Thanks for the help.

@ccoupe
Copy link

ccoupe commented Apr 22, 2014

I've fixed this bug with Shoes3.2 (Linux and Windows)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

10 participants