Debugging technique in Magento: Process of elimination

Introduction:

Debugging is a methodical process of finding and reducing the number of bugs, or defects, in a computer program or a piece of electronic hardware, thus making it behave as expected.

Source: Wikipedia

Nobody is perfect so don’t expect an application to be perfect. As a developer you may face many bugs during your application development, some are easy to trace & fix and some are hard to trace & fix.

Suppose say you got a strange error which doesn’t give any hint of what it could be then what will you do?
Of course, you will try to isolate the error, but how?

Answer: By Process of Elimination

Steps:

Here are some tips for debugging in Magento by process of elimination (I would even say the renaming/commenting techniques):
Step 1. Rename the current theme folder and check if the error is eliminated or not
If the error is eliminated then try to isolate the error by renaming the XML layout or .phtml template files
else go ahead with step 2.

Step 2. Rename the app/code/local folder and check if the error is eliminated or not
If the error is eliminated then try to isolate the error by disabling the local modules one by one
else go ahead with step 3.

Some Notes:
Even you disable all the local modules using the following code in app/etc/local.xml:

<disable_local_modules>true</disable_local_modules>

or
using following code in app/etc/modules/*.xml

<active>false</active> 

This will help you but not much. Suppose consider the case that you have core class overridden in app/code/local/Mage directory.
Do this kind of overriding require any XML declarations?

Answer: Nope.
So, in this case, app/code/local folder renaming can be helpful instead of disabling the module via XML file.

Step 3. Rename the app/code/community folder and check if the error is eliminated or not
If the error is eliminated then try to isolate the error by disabling the local modules one by one
else go ahead with scratching your head 😉

Suppose, for example, you find that the main culprit was some community module. You should try to comment on the different section of config.xml of that module. This will help you in locating the main culprit file. Once the culprit file is found then you can narrow it down by commenting different section of the code until you find that main single line of code. Once the main culprit line/code is found then it’s up to you how to fix.

Hope this article was useful.
Thanks for reading!