All posts

Post 01

The bug wasn't in the code

A production exception I couldn't trace in the code turned out to be users pasting the wrong links. Here's what it changed about how I debug.

As an engineer, when faced with a problem, I often find myself diving deep into the code, methodically trying to identify the issue with a systematic approach. That's what we've been taught. But over the past few weeks, while working on a ticket to fix a bug, I realised that although the error was indeed thrown from the code, there's a more important layer we sometimes overlook: the users behind the software. What seemed like an untraceable bug turned out to be a simple user error.

In this post, I want to share a shift in my approach to debugging, one that keeps user interaction at the forefront.

Lesson learned

The ticket in question was about exceptions being thrown in production. When people tried to open discussions on a customer community site, invalid IDs were being passed to the backend. With the specific class and line of code provided, I began my journey by mapping out:

  • How many exceptions we were getting
  • Which frontend component was passing the discussion ID, and how
  • How the discussion was retrieved from the backend
  • How the article was indexed in the community

Logical steps, right? But even after going through all that, I couldn't find anything technically wrong with the code. So I asked myself: how are users even getting this ID, especially since it isn't valid?

At that point, I started to suspect something bigger. Was there a hardcoded ID somewhere? Since Salesforce IDs are case-sensitive, why was this one coming in lowercase?

After searching high and low, and hitting multiple dead ends, I finally reached out for help. When I spoke to the community moderator, she suggested something that hadn't occurred to me: the user might be trying to post a link from outside the community or the ideas forum.

That was the breakthrough. I had overlooked one crucial factor: the user.

In the end, the issue wasn't in the code. The links users were trying to use were incorrect, either formatted differently or pointing to the wrong object type entirely. For those unfamiliar with Salesforce, each object type has a unique prefix in its ID. For example, a Case ID typically starts with 500, like 500XXXXXXXXXXXXXX.

A new approach

While it's important to dissect the code systematically, we also need to appreciate where the journey begins. Before jumping into the logic, we need to understand the context.

Here's how I plan to approach bugs from now on:

  1. Reproduce the issue in a user context, not just from logs or stack traces.
  2. Check the error message, affected users, and the stack trace.
  3. Start from the surface and trace through the layers, frontend to backend.
  4. Look for recent changes or broken tests in related components.
  5. Identify the likely area causing the issue, or work out whether it's a bug at all.
  6. Make small, testable changes. I like to keep changes under 15 lines before testing. If it's a bug, it usually takes even less.
  7. Fix it properly: write clear, quality tests and leave the code better than you found it.

Simple, right?

Well, that's the ideal path. In reality, it's probably going to be harder. But even when the trail goes cold, don't forget to step back and understand the context of the bug.

That context might just be the insight you're looking for.