Debugging Like a Knucklehead
Pluralsight. I am digging in how to handle versioning for an API and I think I’ve gotten it figured out but it just doesn’t work. Throwing a crazy exception and just isn’t working. I waste four hours trying to figure it out and I am cursing and grunting. The other people in the coffee shop are staring.
I spend a bunch of time on Google trying to find someone with a similar problem but no luck. Looking at the data and walking through the bug with the debugger didn’t yield anything. Desperate, I reach out to Glenn Block himself for an answer. He’s very gracious and agrees to help me out with a quick Skype session.
I tell him the story and he seems shocked. He’s telling me things to try but I’ve tried most of them. I can tell by the look on his face that he doubts that this could be a bug…but it might be. So I told him I’d create a quick reproducible example so I could talk with someone on the team. With some things to try and my assignment to reproduce the problem in isolation, he left me to my own devices.
First thing I did was to create the reproducible case…and it worked. Uh oh. It wasn’t a bug…it was working *exactly* as intended. Soon after I found the offending bug. I had done two important things wrong:
- I didn’t reduce the problem to eliminate my code from the equation. (e.g. create a repo case)
- I didn’t fully read the stack trace of the problem. I skimmed it and assumed where it was throwing the error.
This happens to developers all the time. It’s a knucklehead move for me specifically because this is what I tell developers they have to do. This is part of my debugging speech. I instruct them to reduce and test and repeat until you have the smallest possible set of code that shows the problem or (usually) find the bug in your own code. It works every time…guaranteed. But only when you follow the procedure.
Even more knuckleheaded was not fully reading the stack trace. This would have pointed me to the problem without even creating the repo case. It was my code that was throwing the exception. A dead giveaway. Half-a-day lost because I thought I was smarter than I am.