DEV Community

Cover image for What Was the Moment You Realized the Bug Wasn't Where You Thought It Was?
Den
Den

Posted on

What Was the Moment You Realized the Bug Wasn't Where You Thought It Was?

I've noticed a pattern in almost every bug I've written up here: the fix never ends up where I started looking.

A validation error that looked like a schema problem turned out to be an encoding mismatch three layers upstream. A "frozen" simulator turned out to be working correctly — the bug was an unstated assumption in my evaluation algorithm, not the code executing it. A user's data disappearing turned out to be two browser tabs disagreeing about which one held the truth.

Every time, I started debugging with a theory about where the problem lived, and every time, the actual cause was one layer removed from that theory — not wrong code, but a wrong assumption about which code even mattered.

I don't think this is unique to me. I think it might be the actual shape of most non-trivial bugs: the symptom points at a location, and the location is almost never the cause.

So — what's yours? The moment you were dead certain the bug was in X, spent hours proving X was fine, and found it living quietly in Y instead. Doesn't have to be dramatic. I'm just curious whether everyone's "it wasn't where I thought" story rhymes with mine, or if there's a completely different shape to it depending on the stack.

Top comments (3)

Collapse
 
beusebiu profile image
Eusebiu Balan

Streaks breaking overnight for a handful of users. I spent two days inside the streak code and the streak code was fine. The phone was sending its own timezone and the server was storing plain UTC dates, so anyone far enough east lost a day at midnight.

Now I check what the client actually sent before I read a line of my own logic.

Collapse
 
den0011 profile image
Den

This is exactly the shape I meant — two days inside code that was never
the problem, because both sides were internally consistent on their own.

I hit a version of this in RealFeedApp too — timestamps looked fine in
testing, then started drifting by a day for some users depending on where
they were. Ended up converting everything to UTC at the boundary and never
letting a local timezone touch storage or logic at all. Same instinct as
yours: stop trusting your own layer and check what's actually crossing
the wire first.

Collapse
 
beusebiu profile image
Eusebiu Balan

UTC at the boundary is right for the instant. The part that still bit me is that a day is not an instant.

A streak asks which local date something happened on, and you cannot get that back from a UTC timestamp on its own once it is stored. So now I keep the UTC instant and the offset the client sent, and derive the local date from the two. Storing a bare date was the actual mistake, not storing the wrong timezone.