08 Dec, 2008

Published at 12:09PM

Tagged with golftrac, problems, programming, rails, and ruby

This post has 0 comments

Ruby error: superclass mismatch

I’ve recently upgraded Golf Trac to Rails 2.2.2 (I was running Rails 2.0.2 before). The upgrade went rather smoothly, except for a new “superclass mismatch” error.

I usually define my custom error classes at the top of the class they correspond to. A situation like this, for example:

1
2
3
4
5
6
7
module Golftrac
  class MissingSREG < Error; end
end

class User < ActiveRecord::Base
  # ... raise Golftrac::MissingSREG if ...
end

Where the Error class lives in the lib directory. But anyway, I’m getting a “superclass mismatch” error because of line 2. Supposedly, you get this error when defining a class more than once, with different superclass’s (which make sense).

1
2
class MissingSREG < SimpleError; end
class MissingSREG < ComplexError; end

But as you can see, that’s not the case. And all of the specs pass with flying colors, too, which is odd that this is only picked up during runtime.

As a temporary fix (I hope), I’m removing the error class before its definition.

1
2
3
4
module Golftrac
  remove_const(:MissingSREG)
  class MissingSREG < Error; end
end

It’s the only way I could quickly prevent that error and move on, but naturally, I want to get to the bottom of this.

Have you seen this behavior before? Either with or without a Rails 2.2.2 upgrade? Have any ideas why this is happening?

Comments

Do you have something to say about this post?
Retype the image to the right Spam Hint: Are You Human? Textile Formatting Tips

or

Ryan Heath | Site Management A Ruby on Rails production.

This site is a Formed Function. Formed Function LLC | @formedfunction | Get in Touch