Ruby Error "Superclass Mismatch for Cookie Class" by cgi.rb

I just upgraded my ruby ​​installation on my gentoo server to ruby ​​1.8.6 patchlevel 287 and started getting an error in one of my eRuby applications. The error indicated in the apache error_log file:

[error] mod_ruby: /usr/lib/ruby/1.8/cgi.rb:774: superclass mismatch for class Cookie (TypeError) 

The strange thing is that it works sometimes, but sometimes I get this error. Any ideas?

+4
source share
2 answers

This error occurs when you re-declare a class that has already been declared, most likely because you are loading two different copies of cgi.rb. See a similar problem in Rails .

+2
source

As the error message says, there is an opening of the Cookie class somewhere in the code that uses a different superclass than the one used in the previous definition or opening of the Cookie class.

Even a class definition that does not explicitly indicate a superclass still has a superclass:

 class Cookie end 

This defines the Cookie class with the superclass Object.

I met this error before, and this will happen when you have code trying to reopen a class without specifying a superclass, and the programmer’s assumption is that the class (in this case, Cookie) is already defined, and that it simply opens it, to add some features. But if reopening and defining are in reverse order, you will get this error because the class will already be defined as a subclass of the object, but is trying to redefine or reopen by another superclass. Try this in irb:

 % irb irb(main):001:0> class C < String; end => nil irb(main):002:0> class C; end => nil irb(main):003:0> exit % irb irb(main):001:0> class C; end => nil irb(main):002:0> class C < String; end TypeError: superclass mismatch for class C from (irb):2 

So, you probably should just use grep to define the Cookie class and try to ensure that the files are always required-d in the correct order. It may or may not be easy. :)

+9
source

Source: https://habr.com/ru/post/1277119/


All Articles