DEV Community

Alan Johnson
Alan Johnson

Posted on • Edited on • Originally published at nalanj.dev

1

Bug Pattern: Ignoring the default case

I'm going to be writing up bug patterns as I see them, as a bit of a personal learning project. When I create bugs, what caused me to create them?

This first one I'm going to call Ignoring the default. Imagine this scenario:

  • You find a tricky bug
  • You spend a while debugging it
  • Aha! You finally find the problem. Fix it. You test the reproduction case. You ship the fix.
  • Time elapses.
  • A very common case in your application isn't working correctly.

I did this yesterday. What was the problem? I ignored the default case. I got so focused on fixing the error case that I forgot to test the default case and rushed to shipping the fix.

This actually came up due to two issues:

  • I ignored the default case when I was preparing the fix.
  • My test coverage didn't cover the default case.

In this particular situation I'm not sure a test for the default case would have made that much sense, but still. I ignored the default case.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay