Object::InstanceMethods is a confusing error

So the project I’m working on has multiple databases – which is, in Rails opinion, kinda weird. Lately we’ve been having some issues where one developer will check in a migration that creates a new database and updates the database.example file. Everyone else does an update, tries to run their migrations, and gets an error saying that you can’t overwrite Object::InstanceMethods. What they need to do is add a few more lines to their database.yml file from the example file, but how would they know that unless they saw the database.example file amongst the stream of files that came down when they updated from source control. We need to get better about telling everyone (an email or a shout out to the room) when these get checked in. Because invariably some dev spends a few minutes scratching their head with this perplexing error.

What’s worse is that when I get this error on windows – It’s all over. I update my database file: same error. I drop and re-create all my databases manually: same error. The only thing I’ve found that works is if I kill my whole damn development folder and check out fresh. I realize that this makes no sense at all, but it works. Is windows hiding or caching some file somewhere? No idea. Luckily I’ve been mostly been developing on Linux for the last few days.

This error is another example of something I’ve been struggling with since I started writing Ruby: The errors tend to be unhelpful. Java and other strongly typed languages fail fast. If you give some method the wrong class, it blows up right away. In dynamic langs like Ruby the method doesn’t care what it gets so long as it can respond to the methods it called on it (the famous “duck typing”). Maybe the method just passes it along, or maybe it gets something off that the bad object and tries to do some stuff with it. So you can get pretty far down the stack from where you actually made your error before the interpreter blows up -- Which makes debugging a challenge. Now I know this added flexibility is what makes Ruby so cool. But it’s not without its costs.

Comments

Popular posts from this blog

What's a Good Flog Score?

Point Inside a Polygon in Ruby

SICP Wasn’t Written for You