5 key points for troubleshooting errors for beginners
All projects have bugs. Have you ever encountered a bug that initially seemed impossible? Projects with legacy parts sometimes make developers avoid touching those parts of the system for fear of breaking even more things and see those bugs as “impossible” bugs. I came to Njuškalo as a junior developer and faced such impossible bugs. It was challenging, but I didn’t give up. Here are five points that show how I learned to deal with bugs and turn the impossible into possible:
- Realizing that we have a bug
- Finding its cause
- Fixing the bug
- Performing damage control
- Testing the fix
Each step can be a nightmare, but if you follow these steps, you can fix the bug in half the time.
1. Realizing that we have a bug
The first step is the easiest – a feature isn’t working as intended and it was noticed by an employee, not a user. Instead of a human, we can implement a monitoring tool that will alert us if there is a traffic problem or an error has occurred. Writing automated tests and QA reviews would go a long way in detecting bugs early before they reach production.
2. Finding the root cause
If you are having trouble finding the root cause of a bug, it may indicate that your codebase is not following architectural patterns or has a lot of dead or duplicate code. You may get stuck on a piece of code that looks like it should be in the right place, but actually turns out to be dead code. Dead or duplicate code can result in longer detection times. Organizing your project can help you narrow down potential bug locations. Structuring your project into domains and layers will allow you to easily navigate your code. Descriptive naming can lead you to your bug. If you can find a class by feature name or something similar, the search time is drastically reduced. It is important to ask for help when you get stuck; time is the only resource you cannot get back, your colleague may know a piece of information that can go a long way in finding the bug.
3. Fixing a bug
Fixing a bug is usually easy once you’ve located it. However, the danger lies in the spaghetti code. You may be fixing your bug, but you may also be unintentionally changing the behavior of your application. Bugs are often the result of rushing and tight deadlines. Take your time, check what you’re changing, and analyze how your fix will affect the rest of your application. Remember to apply the Boy Scout Rule (“Always leave the code you’re working on a little better than you found it.”) while fixing a specific section of code. This will help you maintain the readability and health of your codebase.
4. Conduct damage control
As long as your application has a bug, it won’t work as intended, which means your data will sometimes be lost, written incorrectly, or in the wrong place. Some of your data may be lost, but you should implement security measures to minimize data loss and risk. Backing up your database will allow you to recover lost data. Setting up multiple backup databases at different time intervals increases the security of your data. For example, the first backup database, known as the slave, will be an hour behind the master, and the second slave will be a day behind. This gives you enough time to react if there is a problem with your data. In addition to data loss, sometimes an error can interrupt or stop the process, resulting in an unfinished feature. For example, if a user is trying to send a message to a vendor, but there is an error in the code and the message is sent but never received. It is useful to know which users were affected by the error so that we can correct the situation. Creating a logging system will allow us to see which users were affected by the error and the extent of the impact.
5. Testing the solution
Testing your solution should be easy, but sometimes it takes a significant amount of time to write instructions for the QA team. This can be for many different reasons, and the complexity or scope of these reasons can sometimes scare or discourage you from covering your feature with tests. However, testing is the most important step because it gives you a second chance to spot a bug that you may have overlooked. If you get stuck or are unsure of how to test something, you always have colleagues you can ask for advice and who can help you find the right way. Don't rush.
More from the library
Dark Mode Best Practices & Impact on Users
Cobra effect and what we can do to mitigate it
Unleashing the Power of AI: Creating a Neural Network Powered Application