Stupid mistakes: Remember to check the obvious

July 30th, 2009 § 1

On Wednesday I received a call from someone with whom I do business on a regular basis. He was calling to report that something I had coded for him several weeks ago was no longer functioning, and he could not understand why.

Normally when I am being hired to code something, the client doesn’t know a thing about how the code works. So when they call to complain about a bug, my first reaction is usually, “what did you do to it?” (not that my code is perfect, but I stress-test the hell out of code before delivery)

bang-head

Naturally, since I was paid to deliver the code and it was now broken, I promised to deliver a fix immediately. My first step was to load up the production version of the code as it would be presented to the end-user, and test it.

It failed.

My next step was to enable Firebug so I could monitor what was going on behind the scenes. As soon as Firebug was active, the problem seemed to disappear. The code seemed to be working perfectly. I refreshed, cleared my cache, and the code still continued to work just fine.

I called the client back, and explained to him that it must have been a fluke of the server or something else, and not to worry about it. Several minutes later, the he called me back again, claiming it was still broken. I immediately loaded up the page again, with Firebug now disabled, and once again it inexplicably failed.

Are you seeing the pattern here?

Seeing as there was something fishy going on, I decided to review the code thoroughly, all thirty-odd lines of it. I moved some things around, fixed what was a quick hack to originally get the job done faster, and tested.

Nothing.

This particular code (the part giving me the trouble) was a piece of jQuery-flavored JavaScript, performing a bit of AJAX magic. I racked my brains and the code, trying to figure out what the problem could be. Then it dawned on me.

I’d forgotten one of the most basic tenets of writing code: Error checking.

error-console

As I expressed immediately after discovering my problem, this is a very easy but stupid mistake to make. I’d forgotten to remove the debugging code for sending a message to the Firebug console while developing. This made it work just fine in the development environment, and equally fine while trying to figure out the problem, but it never occurred to me to check the Firefox error console.

Lesson learned: Write code, check, double-check, repeat.

End of line.

Tagged: , , , ,

§ One Response to “Stupid mistakes: Remember to check the obvious”

  • Flavio Camus says:

    Believe me , my friend. i did suffer the same. There is a solution for that annoying situation. its a function who catch the console.log request, in case of the console object is not set (a browser without firebug). its quite useful to avoid the problem.

  • § Leave a Reply

What's this?

You are currently reading Stupid mistakes: Remember to check the obvious at Abraham Vegh.

meta