How to debug software

12/12/10

or, “How I Spent Sunday Afternoon”

  1. Write javascript code for a new UI component.
  2. Discover weird bug in new code: every time a mouseenter event occurs on a particular element, a mouseleave event immediately fires on the same element, leading to an endless loop of enter and leave events flickering past.
  3. Spend some time futzing around with logging and breakpoints, finally resorting to selectively disabling each of the most recent code changes, trying to narrow down what’s causing the extra event.
  4. Roll back all the way to last Friday’s version of the code, which you could swear was working fine — but the bug’s still there.
  5. Completely remove the new component from the testbed, leaving only the well-tested framework code that hasn’t been touched in at least a couple of weeks.
  6. Bug’s still there. Start to panic, just a tiny bit: you’re supposed to demo this code to the client on Wednesday (which is why you’re working over the weekend in the first place.)
  7. Check in other browsers — no bug. Check on the windows machine — no bug there, even in Firefox. So, okay, we’ve narrowed it down to the OSX version of Firefox.
  8. Start doing global searches across the entire codebase for anything that could be setting a mouseenter or mouseleave event. In exasperation, disable all of them.
  9. Bug’s still there.
  10. Get up from computer, pour a cup of coffee, put away dozens of scattered toddler toys, vacuum entire house, do physical therapy exercises rather more emphatically than usual. Find cup of tepid coffee still sitting on the counter where you forgot it after pouring.
  11. Sit back down at computer. Oddly enough, the bug is still there.
  12. Revert code to latest version, as it was back in step 1.
  13. Quit Firefox. Restart Firefox. Reload page.
  14. Bug is gone.

THE CALL WAS COMING FROM INSIDE THE DEBUGGER ALL ALONG