Bug Fixing 101

Don't let bugs haunt your dreams

Unfortunately, in any ambitious piece of software, bugs are quite inevitable and can quickly become nightmares. On the other hand, fixing bugs is a very rewarding quest. So let's turn those pains into recurring success!

Step 1: Is There Really a Bug?

When a bug is reported to you, first thing to do is to verify that you really face a bug, meaning that the software is not behaving as expected. Sometimes, you do not know the expected behaviour. In this case, compare observed behaviour with the one you get on a different environment or with some different credentials.

Quite often, some errors can be interpreted as bugs while this is the expected behaviour. In these cases, the question becomes why the user thought this was a bug and what we can do to avoid that. You know that you face a bug when you can proof that the observed behaviour differs from the expected one and that you can clearly expressed the differences.

Step 2: Track the Trace

As in real life, software bugs can leave their marks on their path. So fist look for them!

  • Check our bug tracking system for a potentially related error

  • Search into our bug tracking system for errors faced by the user(s) who reported the bug

  • If this is a bug in the interface (frontend), check into the browser console whether you can find an error

Those footprints will help you understand the bug and to later reproduce it.

Step 3: Reproduce & Fix it

In most cases, a given bug only arises in some very specific scenarios. Understanding the steps and their order that lead to a bug is the most crucial task you have to succeed in order to fix a bug.

To do so, the key here is to observe and then to connect the dots.

There are many things you can have a look at:

  • the data

  • the code

  • the recordings

  • the HTTP requests

  • the logs

  • the environment

  • who were the impacted users

  • when it first occurs

  • recent changes on the codebase.

Once you have a clear understanding of the steps and conditions that lead to your bug, you can start trying to fix it. There is plenty of ressources that focus on that matter but we can of course list the following advices:

  • Read the error carefully

  • Google the error

  • put some breakpoints in your code (debugger, byebug)

Step 5: Test Your Fix

It's good to have confidence in yourself and your code but if you managed to first reproduce the bug, you now can and must check whether it finally flown away. Add some specs so that it will not be accidentally broken in the future. Also be creative and go one step further by trying to break your fix, find some new edge cases to cover.