Finding and Fixing Bugs in Software

Posted by Paul on December 2, 2016

Unfortunately, despite our best efforts, computer software is incredibly brittle (as opposed to being flexible). That means that a small change somewhere can totally break something and prevent anything from working at all.

So when something breaks, it can be easy to panic and imagine something terrible has happened, but often it's something fairly small that's easy to fix.

Having had to fix bugs and issues for many, many years there tends to be a predictable procedure to go through each time which usually ends in finding the root cause of the issue:

  1. Cause the error to happen, and pay attention to what you see.
  2. If there's an error message, Google it. Often this will be enough to find a solution.
  3. If there's no error message, try and find one by checking the error logs. In OpenCart these will be in either /system/logs/error.log or in /error_log or /admin/error_log. Googling this will often get to a solution. If that solution happens to be on Stack Overflow with lots of upvotes then your problem is probably solved.

If there was no error, then it gets a bit harder, we have to identify where the program is failing and you will need to be able to read some code but he's a bit of an overview of the process that a developer may go through:

  1. Based on the URL in the address bar, it may be possible to work out what file is running. In OpenCart, the route URL variable will tell you which "controller" file to start from. If this variable isn't there you could try temporarily disabling SEO URLs to show it.
  2. Start at the very top of the first function to run (usually called index) and print some text and then exit with the "die" function.
  3. In most cases something is output, but if not you may have to do this process from the index.php in the web root.
  4. Keep moving the print and die commands down and refreshing the page until they are not output.
  5. The line before is probably where the error is happening. You'll need to do some tests here to find out what's going wrong but at least you can be fairly sure the error is here.

And if all else fails, get in touch with a friendly PHP developer!

blog comments powered by Disqus