tags:

views:

773

answers:

15

A while back I migrated a ruby webapp (using eRuby - note: Not Rails) to my new server and in the process it seems to have got broken. I get the error "/usr/lib/ruby/1.8/tempfile.rb:12: superclass mismatch for class Tempfile (TypeError)".

I can't see what changed in the migration - all the code stayed exactly the same. I've tried stripping the code down somewhat but it still doesn't work.

Any ideas what might be wrong or where else to look?

Basically the webapp is using the BBC's Traffic Information RSS feeds and searching them to find traffic reports relevant to certain roads. Because of this it uses 'rss/1.0', 'rss/2.0' and 'open-uri'.

Cheers,

Robin

UPDATE:

After more investigation I have found that this error does not occur when I'm calling the methods in my classes from a normal ruby script (as opposed to a .rhtml file). Therefore it seems to be a problem with eRuby. Anyone any ideas?

A: 

What version of ruby are you using?

Craig
A: 

Ruby 1.8.6

I don't know what version of ruby the old server was running (as it has now been wiped) but it may have been slightly earlier - I'm not sure.

robintw
A: 

Looking at this thread, it could be that you have more than one Tempfile class being defined. Although the end of the thread suggests that perhaps your app is not restarting. I am guessing killing the processes (or a reboot), does not resolve the issue.

How much did you try stripping it down? What about rebuilding your code, trying to find the offending line of code that causes the error. My guess is a misbehaving module.

Craig
A: 

The interesting thing is that this happens even in a non-object-oriented app where I couldn't have been defining a class called Tempfile. It still happens even in my refactored OOP version (I did the refactoring before I migrated the code and got the error).

If I'm not defining the class Tempfile then it seems like one of my 'requires' is...but the only requires I use are part of the standard ruby library (rss and open-uri).

Any other ideas?

I will do more digging around with reducing the app and try and see where it fails.

Robin

Update: No a restart of the process or a reboot of the machine doesn't solve this issue.

robintw
A: 

What about a simple ruby script, that has no includes? If that works try adding in each requires and see if either break the app, and then both and see if together they don't play nice.

Craig
A: 

I've done a bit more working around and I've tried running my code from outside of the eRuby environment (ie. copying some of the code from the .rhtml files and putting it in a normal .rb file that can be executed at the command line) and I've found that it works...which is interesting.

I guess that we're looking at a slightly different issue here - as in something that works in a standard ruby file, but not in eRuby. Anybody have any idea what's going on here? Could it be some kinda security/permissions issue?

PS: Should I change the question title (is that possible anyway?) or open a new question for this as the topic has changed a bit?

robintw
+1  A: 

It definitely sounds like it could be an eRuby problem, which unfortunately I don't have any experience with. The lack of results searching for the error, and the lack of responses to the few I have found leads me to believe it is an install/configuration error. Perhaps something unexpected happened, installing a gem that eRuby doesn't expect, etc. That is causing bad stuff.

Uninstalling and reinstalling is my last though. I would re-ask the question, unless you can get someone with more reputation in here to edit your post. Good luck.

Craig
A: 

Thanks for your help Craig.

robintw
A: 

In case anyone else looks at this then I have reinstalled Ruby and done a gem update, and the problem is still there.

Any other ideas?

robintw
A: 

Tempfile is a standard library class that's defined like so:

class Tempfile < DelegateClass(File)
   # (implementation)
end

DelegateClass returns a new class every time it's executed, so if this definition were read twice, you'd get the error you're seeing. I would modify the standard library file tempfile.rb to show a stack trace when it's being loaded so you can see if and why it's being loaded more than once.

Curt Hagenlocher
A: 

How would I modify it to get a stacktrace? Is there a relatively easy way to do that?

robintw
A: 

How big is your code? Do you want to try and find the smallest possible code base that duplicates the error and paste it in the question?

It sounds like something is not playing nice with the packages. Sounds like perhaps a corrupt installation or bad code.

Craig
A: 

Ahhh - I have some more information.

I've reduced my code to:

<html>
<head>
<title>Test page</title>
</head>

<body>
<%
require 'open-uri'
require 'rss/1.0'
require 'rss/2.0'

source_url = 'http://www.bbc.co.uk/'

open(source_url)

%>
</body>

</html>

All that lot, shoved in a .rhtml file and navigated to gives the error. I've done a bit more investigating and it seems that anything relating to using open-uri gives the error. For example regardless of what I do with the data that comes from the open command (in my actual code there is a do-end construct which actually collects the data). Any idea why this open-uri stuff isn't working from within eRuby? Is it some kind of security issue where web-based apps aren't allowed to download from other websites?

robintw
A: 

I found some potentially helpful info here

It seems that eruby's build (eruby-1.0.5-i386-mswin32-1.8.zip) has .compatibility problem with current ruby (1.8.6-p111)

And additional info here

Just a note:

erb - bundled in one-click erubis - gem install erubis

use erb.cmd or erubis.cmd (or ruby.exe c:/ruby/bin/erubis ) instead of eruby.exe

Craig
A: 

Thanks. Those links don't actually seem to work at the moment - but with a bit of googling I think I found the same thread elsewhere.

I'm not sure whether it's just the windows build that has a problem with that version of ruby - I'm using linux.

I've tried installing erubis and getting that to work - but it doesn't seem to want to play nicely with Apache. I think I probably need to do a bit more work on that sometime soon and try and get it to start working nicely.

I'll keep you updated. Meanwhile, anyone got any other ideas?

robintw