Handling Magento errors
Saturday, 15 May 2010Magento 1.4 ships with a new feature, which effectively hides errors from your visitors. If some kind of error occurs - a PHP Fatal Error, or PHP Notice Error, or database error - the actual error is written to file and not shown on screen. But when developing Magento sites, this behaviour might actually become annoying. Luckily you can easily re-enable the error-displaying again.
Peeking at the files
When an error occurs, a dump of the error is stored within the Magento folder var/reports. By inspecting those files, you will find the actual error but also a trace of the PHP-code producing the error. Some examples of what this error might contain:
- SQL-commands containing some kind of error
- A call to a non-existing PHP-class (perhaps because an extension was removed)
- Incorrect PHP-variables
Showing errors anyway
Displaying the error on screen is much easier to work with. To enable the error-displaying again (just like with pre-1.4 versions), navigate to the errors-folder in the Magento root, and rename the file local.xml.sample to local.xml. The XML-file should contain a line similar to this:
<config>
<skin>default</skin>
<report>
<action>print</action>
<trash>leave</trash>
</report>
</config>
You can see that the action here is configured to print the message on screen, while the original dump is also left on the filesystem (in var/cache). You could also change the XML-code a bit to remove the dump-file instead:
<trash>delete</trash>
Mail me if an error occurs
Even cooler is that the XML-code also allows you to define an email-address to which mail should be sent if some error occurs:
<config>
<skin>default</skin>
<report>
<action>email</action>
<subject>Whoops, something went wrong in Magento</subject>
<email_address>info [5a]</email_address>
<trash>delete</trash>
</report>
</config>
Those of you who have wondered why errors were displayed using the original skin, can also see that the skin can be changed as well here:
<skin>myskin</skin>
Hope you find this all usefull.
